all ip addresses of machines in the local network

damacy wegein at gmail.com
Fri Sep 1 02:17:47 EDT 2006


Amit Khemka wrote:
> > in my program so far, multiple threads (255 threads in total) spawned
> > at once with each one of them trying to call socket.gethostbyaddr(ip)
> > function. i.e. if exception thrown, no machine found. i used .join() to
> > wait for the threads to terminate. it's fully working however the
> > problem is that it's too slow. it takes approx. 14 seconds to process
> > (i tried using 'ping' but it's even slower.).
> >
> > my question is.. is there a way to improve performance of the program
> > if i know what the port number would be? in my case, the port number
> > will always be constant although i have no clue on what ip addresses
> > would be (that's the reason all of 255 different addresses must be
> > tested).
> >
> > i tried the same function with the port number specified,
> > gethostbyaddr(ip:portno), but it is even 10-second slower than using
> > the same function without a port number specified (i.e. approx. 25
> > seconds to complete).
>
> You can save some (DNS) overheads by escaping the call
> "gethostbyaddr", assuming you are not interested in knowing the
> 'Names' of the machines in your Network. And directly attempt to find
> the machines which are listenting on the specified port. A simple way
> of
> doing this would be to use socket.connect((ip, port)), if the
> connections succeds you have
> your machine !
>
> ( There are various other ways of scanning ports, have a look at:
> http://insecure.org/nmap/nmap_doc.html#connect )
>
> Though I am not sure how 'fast' it would be. Also remember that the
> time in scanning is affected by network-type,
> response-time-of-remote-machine, number-of-machines scanned etc.
>
> I would still be interested, in seeing how nmap(with some smart
> options) compares with the python code. ( In my network "nmap
> -osscan_limit -p 22 -T5 Class_D_Network" completes in 1.5 seconds !)
>
> cheers,
> amit.
> --
> ----
> Amit Khemka -- onyomo.com
> Home Page: www.cse.iitd.ernet.in/~csd00377
> Endless the world's turn, endless the sun's Spinning, Endless the quest;
> I turn again, back to my own beginning, And here, find rest.

hello.

here are my test results;

1. using nmap with the options specified above: approx. 50 seconds or
longer
2. using socket.connect((ip, port)): approx. 26 seconds
3. using socket.gethostbyaddr(ip): approx. 14 seconds

all three above use multiple threads.

and also, i tried using (in and out) queues to detect the threads
termination (instead of .join()), however, it's also very slow and it
needs to have deadlock detection mechanism implemented in it which
would probably lower the performance of the program.

hmm...




More information about the Python-list mailing list