Last active
April 12, 2017 09:05
-
-
Save 0x9090/a7aba0778a3ae3fc35f738bcecdecaf2 to your computer and use it in GitHub Desktop.
Simple Socket Listener
This file contains 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, sys | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
port = 6675 | |
server_address = ("0.0.0.0", port) | |
sock.bind(server_address) | |
sock.listen(1) | |
while True: | |
print "~ Waiting For Connection on port:", port | |
connection, client_address = sock.accept() | |
try: | |
print "~ Connection From:", client_address[0] | |
while True: | |
data = connection.recv(16) | |
print "%s" % data | |
if data: | |
print "~ Recieved Data" | |
connection.sendall("1") | |
else: | |
print "~ No More Data From:", client_address[0] | |
break | |
finally: | |
connection.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment