in reply to Suggestions & Improvements on a portscanner using IO::Socket

Hello everybody,

Could someone suggest a way to make the same script but using threads (or scanning several ports at the 'same' time)?

I have no idea on how it should work, I looked a little at IO::Select for now... I dont need a script, i'd really like to come up with one by myself, but a few hints would be greatly appreciated.

Thanks
Freddo

Replies are listed 'Best First'.
Re: Re: Suggestions & Improvements
by Anonymous Monk on May 08, 2002 at 09:43 UTC
    freddo, Use fork to handle the packet send/recv routines. elias
      As suggested, fork will do the trick. The thing you need to be careful of is not swarming the machine with forks. Up to a point, it will get the job done faster, but isn't very friendly to the other programs.

      Also, at some point you probably get diminishing returns until you have so many forks that none of them get done in a reasonable amount of time.

      So...keep a counter of how many forks you have launched and don't start new ones until some have been reaped. (see waitpid...). On my own scanner and on various stress testing clients, I have provided the number of forks to be defined at command line (or defaulted to 5 at a time). See nmap.

      IO:Select is not what you want here. Not only is it not threading or forking, but is actually used to multiplex reading and writing to/from handles that have already been established. Once you get the scanner done, write a multiplexing server for some real fun and a good introduction to network server coding. :-)

      Have a blast!

Re: Re: Suggestions & Improvements
by elwarren (Priest) on May 08, 2002 at 20:50 UTC
    You could take a look at Parallel-ForkManager, it does just what you want. You could easily adapt the ping example to opening multiple ports...