EvilZone

Programming and Scripting => Scripting Languages => : Clone February 02, 2014, 10:12:35 AM

: Question:Subnet port scanner
: 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:
: (Python)
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()           
: Re: Question:Subnet port scanner
: proxx February 02, 2014, 11:12:54 AM
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?
: Re: Question:Subnet port scanner
: Clone February 02, 2014, 07:24:59 PM
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.
: Re: Question:Subnet port scanner
: proxx February 02, 2014, 07:32:17 PM
You just let it connect with all the adresses in the subnet.
for I  in range(1,254):
               Do something here
: Re: Question:Subnet port scanner
: Clone February 02, 2014, 07:38:55 PM
i see... thanks i really appreciate the advice  :)