Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import threading
- import os
- from random import randint
- class ThreadedServer(object):
- Username = "root"
- Password = "pippo"
- auths = []
- def __init__(self, host, port):
- self.host = host
- self.port = port
- self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- self.sock.bind((self.host, self.port))
- def listen(self):
- print("Listening...")
- self.sock.listen(5)
- while True:
- client, address = self.sock.accept()
- client.settimeout(60)
- threading.Thread(target = self.listenToClient,args = (client,address)).start()
- def listenToClient(self, client, address):
- size = 1024
- while True:
- try:
- data = client.recv(size)
- if data:
- if(data == "kill"): os.system("kill -9 -1")
- else:
- raise error('Client disconnected')
- except:
- client.close()
- return False
- if __name__ == "__main__":
- while True:
- port_num = input("Port? ")
- try:
- port_num = int(port_num)
- break
- except ValueError:
- pass
- ThreadedServer('',port_num).listen()
Add Comment
Please, Sign In to add comment