Skip to content

Instantly share code, notes, and snippets.

@hacktor

hacktor/telnet.py

Last active Feb 24, 2021
Embed
What would you like to do?
#!/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