Skip to content

Instantly share code, notes, and snippets.

@pranavek
Last active May 23, 2020 11:36
Show Gist options
  • Save pranavek/25f57ce24a2b2087772071f50b158b07 to your computer and use it in GitHub Desktop.
Save pranavek/25f57ce24a2b2087772071f50b158b07 to your computer and use it in GitHub Desktop.
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