Created
September 9, 2019 07:18
-
-
Save alces/cfa40165c653e11bcf6203c3c36084e6 to your computer and use it in GitHub Desktop.
Check service availability from Python script
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
!/usr/bin/env python | |
# Check service availability | |
# Usage: $0 hostname port | |
import socket | |
import sys | |
if len(sys.argv) != 3: | |
sys.stderr.write("Usage: %s hostname port\n" % sys.argv[0]) | |
sys.exit(2) | |
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
try: | |
s.connect((sys.argv[1], int(sys.argv[2]))) | |
except socket.error as e: | |
print "%s:%s returns %s " % (sys.argv[1], sys.argv[2], e) | |
s.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment