Skip to content

Instantly share code, notes, and snippets.

@cooperq
Created August 26, 2012 04:13
Show Gist options
  • Save cooperq/3473951 to your computer and use it in GitHub Desktop.
Save cooperq/3473951 to your computer and use it in GitHub Desktop.
import socket
HOST = '' # Symbolic name meaning all available interfaces
PORT = 50008 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
old_port = 1
while 1:
conn, addr = s.accept()
print 'Connected by', addr
new_port = addr[1]
difference = new_port - old_port
print "port change of: " + str(difference)
data = conn.recv(1024)
if data:
print data
conn.close()
old_port = new_port
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment