Skip to content

Instantly share code, notes, and snippets.

@aeppert
Created October 1, 2015 17:08
Show Gist options
  • Select an option

  • Save aeppert/5a1a163a82ee5d7a96f3 to your computer and use it in GitHub Desktop.

Select an option

Save aeppert/5a1a163a82ee5d7a96f3 to your computer and use it in GitHub Desktop.
Attempt to verify a host is alive via connecting to a supplied TCP port
def port_ping(host, port):
ret = False
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect((socket.gethostbyname(host), int(port)))
sock.close()
ret = True
except socket.error:
ret = False
return ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment