> 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. -- http://mail.python.org/mailman/listinfo/python-list