EvilZone
Programming and Scripting => Scripting Languages => : Clone February 02, 2014, 10:12:35 AM
-
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()
-
Good,
You should add shorter timeouts for a connect scan , it will take forever otherwise.
Suggest you take a look at SYN and ACK scanning.
Scapy might offer some help here.
You need help on what?
-
Thanks I will add shorter timeouts its only a draft i posted.anyway I was thinking in terms of subnets,so how would you port scan a subnet lets say my ip address is "10.0.6.123" and i want to port scan ip "10.0.6.140" how would i script such a port scanner.In other words how do you scan ips in the same subnet.
-
You just let it connect with all the adresses in the subnet.
for I in range(1,254):
Do something here
-
i see... thanks i really appreciate the advice :)