Skip to content

Instantly share code, notes, and snippets.

@zhangchunlin
Forked from defnull/tcping.py
Created June 20, 2016 10:08
Show Gist options
  • Save zhangchunlin/6f8aa3c8e0c0acf1d3af1becc5ee0146 to your computer and use it in GitHub Desktop.
Save zhangchunlin/6f8aa3c8e0c0acf1d3af1becc5ee0146 to your computer and use it in GitHub Desktop.
TCPing
def ping(server, port):
''' Check if a server accepts connections on a specific TCP port '''
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((server, port))
s.close()
return True
except socket.error:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment