Skip to content

Instantly share code, notes, and snippets.

@Xifeng2009
Created January 8, 2019 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xifeng2009/789ef3b4bdc38032717e215f8a95031e to your computer and use it in GitHub Desktop.
Save Xifeng2009/789ef3b4bdc38032717e215f8a95031e to your computer and use it in GitHub Desktop.
import socket
import threading
class Connection:
def __init__(self, cid, conn, addr):
self.cid = cid
self.conn = conn
self.addr = addr
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('localhost', 1337))
s.listen(5)
cid = 0
clients = {}
def listener(s):
global cid, clients
while True:
conn, addr = s.accept()
print("[INFO] Connection From {}:{}".format(addr[0], addr[1]))
cid +=1
clients[cid] = Connection(cid, conn, addr)
def main():
t = threading.Thread(target=listener, args=(s,))
t.setDaemon(True)
t.start()
while True:
print("[INFO] Current Number of Clients: {}".format(cid))
try:
ccid = int(input("Choose a Client: "))
except:
continue
prompt = input("Zombie[{}] >>> ".format(ccid))
if not prompt:
continue
if prompt == 'q':
break
elif prompt == 'clients':
print("[INFO] Total Clients: {}".format(len(clients)))
else:
try:
clients[ccid].conn.send(bytes(prompt, encoding='utf-8'))
print("[INFO] Send Succees.")
print(clients[ccid].conn.recv(1024).decode('utf-8'))
except socket.error as e:
print("[INFO] Send Failed: {}".format(e[:50]))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment