hxbsy has asked for the wisdom of the Perl Monks concerning the following question:
####################################################use IO::Handle; use Socket; use threads; use IO::Socket::INET; open(pctxt,'./pc.txt')||die "error open $!"; while($read_data = <pctxt>) { chomp; $read_data=~s/\s//g; $read_data=~s/" "//g; thread($read_data); } close(pctxt); sub thread { my $net = shift; my @ip = (1..255); my $port = 12345; my $thr0 = threads->new(\\&scan, "$net@ip[0..63]", $port); my $thr1 = threads->new(\\&scan, "$net@ip[64..127]", $port); my $thr2 = threads->new(\\&scan, "$net@ip[128..191]", $port); my $thr3 = threads->new(\\&scan, "$net@ip[192..254]", $port); $thr0->join(); $thr1->join(); $thr2->join(); $thr3->join(); } sub scan { my (@hosts, $port) = @_; foreach my $host (@hosts) { my $socket = new IO::Socket::INET ( PeerHost => $host, PeerPort => $port, Proto => "tcp", ); if($socket) { print $port,"is open!\\n"; $socket->close(); } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: About "thread failed to start:"
by BrowserUk (Patriarch) on Apr 09, 2015 at 06:54 UTC | |
by hxbsy (Novice) on Apr 09, 2015 at 08:10 UTC | |
by marinersk (Priest) on Apr 09, 2015 at 12:25 UTC |