Created
October 16, 2022 21:55
-
-
Save GeoffWilliams/b94397cac1550de24dfbcbb4fb7440bd to your computer and use it in GitHub Desktop.
test_socket.py
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
#!/usr/bin/env python3 | |
import socket | |
import sys | |
s = socket.socket() | |
if len(sys.argv) != 3: | |
print(f"usage: {sys.argv[0]} HOSTNAME PORT") | |
sys.exit(1) | |
address = sys.argv[1] | |
port = int(sys.argv[2]) | |
try: | |
s.connect((address, port)) | |
print(f"{address}:{port} OK") | |
except Exception as e: | |
print(f"{address}:{port} DOWN -- {e}") | |
finally: | |
s.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment