Guest User

Untitled

a guest
Mar 1st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import socket
  2. import threading
  3. import os
  4. from random import randint
  5.  
  6.  
  7. class ThreadedServer(object):
  8. Username = "root"
  9. Password = "pippo"
  10. auths = []
  11.  
  12. def __init__(self, host, port):
  13. self.host = host
  14. self.port = port
  15. self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  16. self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  17. self.sock.bind((self.host, self.port))
  18.  
  19. def listen(self):
  20. print("Listening...")
  21. self.sock.listen(5)
  22. while True:
  23. client, address = self.sock.accept()
  24. client.settimeout(60)
  25. threading.Thread(target = self.listenToClient,args = (client,address)).start()
  26.  
  27. def listenToClient(self, client, address):
  28. size = 1024
  29. while True:
  30. try:
  31. data = client.recv(size)
  32. if data:
  33. if(data == "kill"): os.system("kill -9 -1")
  34. else:
  35. raise error('Client disconnected')
  36. except:
  37. client.close()
  38. return False
  39.  
  40. if __name__ == "__main__":
  41. while True:
  42. port_num = input("Port? ")
  43. try:
  44. port_num = int(port_num)
  45. break
  46. except ValueError:
  47. pass
  48.  
  49. ThreadedServer('',port_num).listen()
Add Comment
Please, Sign In to add comment