Advertisement
Guest User

Untitled

a guest
Apr 18th, 2018
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import socket, string, time, thread, math, re, time
  4.  
  5. SERVER = 'irc.root-me.org'
  6. PORT = 6667
  7. NICKNAME = 'malhac_a'
  8. CHANNEL = '#root-me_challenge'
  9.  
  10. def main():
  11. global IRC
  12. IRC = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  13. print("Connecting to server: " + SERVER)
  14. IRC.connect((SERVER, PORT))
  15. Listener()
  16. #thread.start_new_thread(Listener(),("Thread No:1",2))
  17.  
  18.  
  19. def login(nickname, username="malhac_a", password = None, realname="malhac_a", hostname="malhac_a", servername=SERVER):
  20. send_data(('USER ' + ' ' + username + ' ' + hostname + ' ' + servername + ' ' + realname + '\r\n'))
  21. #send_data('USER %s' % NICKNAME)
  22. send_data('NICK %s' % NICKNAME)
  23.  
  24. def send_data(command):
  25. print("Sending command: " + command + "\n")
  26. IRC.send(command + '\n')
  27.  
  28. def closeSocket():
  29. print("Closing socket")
  30. IRC.close()
  31.  
  32. def Listener():
  33. login(NICKNAME)
  34. bufferConnection = IRC.recv(4096)
  35. send_data('JOIN %s' % CHANNEL)
  36. matching = False
  37.  
  38. while (matching == False):
  39. send_data('PRIVMSG Candy : !ep1')
  40. bufferMsg = IRC.recv(8096)
  41. print("Receiving command: " + bufferMsg)
  42. if re.match(":Candy!Candy@root-me.org*", bufferMsg):
  43. matching = True
  44.  
  45. res = calcul(bufferMsg)
  46. send_data("PRIVMSG Candy : !ep1 -rep %s" % res)
  47. bufferMsg = IRC.recv(8096)
  48. print("Receiving responde: " + bufferMsg)
  49. closeSocket()
  50.  
  51. def calcul(bufferMsg):
  52. tabValue = bufferMsg.split("/")
  53. nb2 = tabValue[1]
  54. nb2 = nb2.replace(" ","")
  55. nb2 = nb2.replace("\n","")
  56.  
  57. tmp = tabValue[0].split(":")
  58. nb1 = tmp[2]
  59. nb1 = nb1.replace(" ", "")
  60.  
  61. var1 = math.sqrt(float(nb1))
  62. var2 = var1 * float(nb2)
  63. final = round(var2, 2)
  64.  
  65. print (final)
  66. return float(final)
  67.  
  68. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement