Created
October 16, 2022 21:55
test_socket.py
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 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