Created
March 16, 2016 13:17
-
-
Save tjt263/bada3d83b4c9eb8f8758 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import socket | |
import threading | |
bind_ip = raw_input("bind ip: ") | |
bind_port = int(raw_input("bind port: ")) | |
# create a socket object | |
server = socket.socket(socket.AF_INET,socket.SOCK_STREAM) | |
# bind the server | |
server.bind((bind_ip,bind_port)) | |
server.listen(5) | |
print "[*] Listening on %s:%d" % (bind_ip,bind_port) | |
# client handling thread | |
def handle_client(client_socket): | |
# print data sent from client | |
request = client_socket.recv(1024) | |
print "Received: %s" % request | |
# send back a packet | |
client_socket.send("ACK!") | |
client_socket.close() | |
while True: | |
client,addr = server.accept() | |
print "[*] Accepted connection from: %s:%d" % (addr[0],addr[1]) | |
# spin up our client thread to handle incoming data | |
client_handler = threading.Thread(target=handle_client,args=(client,)) | |
client_handler.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment