Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import sys
import socket
from datetime import datetime
if(len(sys.argv) < 2):
print("Usage: python3 %s <host>"%sys.argv[0])
sys.exit(1)
ip = socket.gethostbyname(sys.argv[1])
try:
print("Started the port scanning at ",datetime.now())
for port in range(20,81):
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.settimeout(1)
open = sock.connect_ex((ip,port))
print("Cheking for port %d"%port)
if open == 0:
print("The port %d is open"%port)
print("Port scanning end at ",datetime.now())
except KeyboardInterrupt:
print("I'm interrupted, mayday, mayday..")
sys.exit(1)
except socket.gaierror:
print("Cannot resolve hostname!")
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.