Skip to content

Instantly share code, notes, and snippets.

@roman-neuhauser
Created March 2, 2014 10:41
Show Gist options
  • Save roman-neuhauser/9304756 to your computer and use it in GitHub Desktop.
Save roman-neuhauser/9304756 to your computer and use it in GitHub Desktop.
import socket
ip = '127.0.0.1'
base = 8000
end = base + 10
[s, t, u] = [socket.socket() for i in '123']
def bind(sock, port):
sock.bind((ip, port))
bind(s, base)
bind(t, base + 1)
port = base
while port < end:
try:
bind(u, port)
print("bound to %(port)d" % locals())
break
except socket.error, e:
port += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment