Skip to content

Instantly share code, notes, and snippets.

@kgriffs
Forked from jmvrbanac/unused.py
Created January 20, 2020 22:47
Show Gist options
  • Save kgriffs/74885ea0fdf5ccec0e3167be82ae732d to your computer and use it in GitHub Desktop.
Save kgriffs/74885ea0fdf5ccec0e3167be82ae732d to your computer and use it in GitHub Desktop.
Get Unused Port
def get_unused_port():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('localhost', 0))
_, port = sock.getsockname()
sock.close()
return port
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment