I need help i started python network prog and wanted to know how you could port scan a hosts in a subnet for open ports.The example of my dried up port scanner,again just a simple one:
import socket as sock
s=sock.socket()
Target_ip=raw_input("Enter target address:")
start=input("Enter starting port:")
end=input("Enter ending port:")
if start>end:
print"Error:Ending port<start port\n"*5
else:
print"Scanning ",Target_ip,"..."
target_ip=sock.gethostbyname(Target_ip)
try:
while start<=end:
r=s.connect_ex((target_ip,start))
if r==0:
print"port ",start,":OPEN"
else:
print "port ",start,":CLOSED"
start=start+1
except:
print"The following errors might have occured 1.)You are not connected to the network.\n2.)Wrong Address\n"
else:
print"End of scan."
s.close()