Created
September 8, 2016 20:37
-
-
Save d6e/acdcb390dc24d87c1392bd5a371588c1 to your computer and use it in GitHub Desktop.
Checks that a given tcp port is open.
This file contains 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
import socket | |
import sys | |
def tcp_check(host, port=22): | |
ClientSocket = socket.socket() | |
try: | |
ClientSocket.connect((host, int(port))) | |
return_flag = True | |
except socket.error: | |
return_flag = False | |
finally: | |
ClientSocket.close() | |
return return_flag | |
host = sys.argv[1] if len(sys.argv) == 3 else 'localhost' | |
port = sys.argv[2] if len(sys.argv) == 3 else 22 | |
print "using host: {} with port: {}".format(host, port) | |
print tcp_check(host, port) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment