Skip to content

Instantly share code, notes, and snippets.

@hacktor
Last active February 24, 2021 16:53
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 hacktor/bcef9dc5c3ce62e06a28bc8d8266065e to your computer and use it in GitHub Desktop.
Save hacktor/bcef9dc5c3ce62e06a28bc8d8266065e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import sys
import socket
from contextlib import closing
def check_socket(host, port):
with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as sock:
sock.settimeout(1)
if sock.connect_ex((host, port)) == 0:
print("Port is open")
else:
print("Port is not open")
if len(sys.argv) != 3:
print("Usage: %s <host> <port>" % sys.argv[0])
sys.exit()
check_socket(sys.argv[1],int(sys.argv[2]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment