Simple TCP Scanner
from socket import *
from sys import argv,exit
open_port=[]
def check_port(sip,sport):
s = socket(AF_INET, SOCK_STREAM)
s.settimeout(0.001)
try:
s.connect((sip,sport))
open_port.append(sport)
except KeyboardInterrupt:
print("Scanning Was Terminated.")
exit()
except:
pass
s.close()
def show_oports():
print "open tcp ports is:"
j = 1
if len(open_port) > 0:
for i in open_port:
print "%d.%s is open." % (j,i)
j += 1
else:
print "is nothing."
port = argv[2]
ip = str(argv[1])
ports = port.split("-")
if len(ports) == 2:
for i in range(int(ports[0]),int(ports[1])):
check_port(ip,i)
elif len(ports) == 1:
check_port(ip,int(ports[0]))
show_oports()
#single port scan
python <source file>.py 192.168.1.1 443
#range port scan
python <source file>.py 192.168.1.1 1-65535
Last updated on 26 Oct 2020
Published on 23 Nov 2018