Created
June 20, 2020 05:28
-
-
Save SudhenduP/0f0425aa5f90f2203a3af94b139ad165 to your computer and use it in GitHub Desktop.
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
def check_server(address, port): | |
# Create a TCP socket | |
timeout = 40 #timeout in seconds | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
#s.settimeout(timeout) | |
print ("Attempting to connect to %s on port %s" % (address, port)) | |
try: | |
s.connect((address, port)) | |
#print ("Connected to %s on port %s" % (address, port)) | |
return "Connected to %s on port %s" % (address, port) | |
except socket.error as error: | |
#print ("Connection to %s on port %s failed: %s") | |
return "Connection to %s on port %s failed: %s" % (address, port, error) | |
finally: | |
s.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment