Skip to content

Instantly share code, notes, and snippets.

@defnull
Created December 4, 2011 21:11
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save defnull/1431288 to your computer and use it in GitHub Desktop.
Save defnull/1431288 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