Last active
May 23, 2020 11:36
-
-
Save pranavek/25f57ce24a2b2087772071f50b158b07 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
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