Skip to content

Instantly share code, notes, and snippets.

@fallenleavesguy
Forked from defnull/tcping.py
Created February 18, 2019 04:49
Show Gist options
  • Save fallenleavesguy/161e13bbfa4f7a479602a20780578dc9 to your computer and use it in GitHub Desktop.
Save fallenleavesguy/161e13bbfa4f7a479602a20780578dc9 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