Skip to content

Instantly share code, notes, and snippets.

@GeoffWilliams
Created October 16, 2022 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GeoffWilliams/b94397cac1550de24dfbcbb4fb7440bd to your computer and use it in GitHub Desktop.
Save GeoffWilliams/b94397cac1550de24dfbcbb4fb7440bd to your computer and use it in GitHub Desktop.
test_socket.py
#!/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