Check if a local TCP port is available

Home   »   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')

Leave a Reply

Your email address will not be published. Required fields are marked *