P has asked for the wisdom of the Perl Monks concerning the following question:

Hi all!

My question is how i can accelerate the scanner? It reads a file that has ips

#!/usr/bin/perl use IO::Socket; my $dir = $ARGV[0]; my @ports = qw(8080 1080 31337 6588 3128 81); my $i = 0; my $time = time; open(READ,"<".$dir.""); while(<READ>) { chomp($_); $i++; print "".$i." · ".$_."\n"; foreach my $port (@ports) { my $is_proxy = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $_, PeerPort => $port, Timeout => 1, ) or next; print "".$i." · ".$_." (".$port.")\n"; $is_proxy->close; last; } } close(READ); my $time_ = time - $time; print "IPs: ".$i." · Time: ".$time_."\n"; exit();

Replies are listed 'Best First'.
Re: IPs' Scanner
by hardburn (Abbot) on Jan 19, 2004 at 22:07 UTC

    You can download nmap and not worry about it.

    ----
    I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
    -- Schemer

    : () { :|:& };:

    Note: All code is untested, unless otherwise stated

Re: IPs' Scanner
by Abigail-II (Bishop) on Jan 19, 2004 at 22:09 UTC
    My question is how i can accelerate the scanner?
    I'd start by leaving out the concatenation of empty strings, which you are doing no less than three times in the code. I wonder why you do this.

    Futhermore, the bottleneck in this code is most likely to be the network - and more specific, the latency. The most obvious way is to do all this in parallel. You might want to use fork() or a select() loop. Or threads if you want to be buzzword compliant.

    Abigail

    A reply falls below the community's threshold of quality. You may see it by logging in.