Last active
February 24, 2021 16:53
-
-
Save hacktor/bcef9dc5c3ce62e06a28bc8d8266065e to your computer and use it in GitHub Desktop.
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 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