Created
October 1, 2015 17:08
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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