Skip to content

Instantly share code, notes, and snippets.

@leepro
Created July 31, 2014 23:18
Show Gist options
  • Select an option

  • Save leepro/b4e754965768ddcd1862 to your computer and use it in GitHub Desktop.

Select an option

Save leepro/b4e754965768ddcd1862 to your computer and use it in GitHub Desktop.
find a open port
def get_open_port():
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("", 0))
s.listen(1)
port = s.getsockname()[1]
s.close()
return port
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment