Skip to content

Instantly share code, notes, and snippets.

@highfestiva
Created May 4, 2021 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save highfestiva/fde899d24e6ce37c115d3c3767f8b040 to your computer and use it in GitHub Desktop.
Save highfestiva/fde899d24e6ce37c115d3c3767f8b040 to your computer and use it in GitHub Desktop.
Check if a local TCP port is available
#!/usr/bin/env python3
import socket
import sys
host,port = sys.argv[1].split(':')
port = int(port)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host,port))
s.listen(1)
s.close()
print('ok')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment