#!/usr/bin/perl -w #use strict; use warnings; use IO::Handle; use Socket; use threads; use IO::Socket::INET; use Net::Ping; open(pctxt,'./pc.txt')||die "error open $!"; open(pc_log, ">./pclog.txt")||die "error open $!"; my $stime = time; while($read_data = ) { #chomp; $read_data=~s/\s//g; $read_data=~s/" "//g; thread($read_data); } my $etime = time; my $diff = $etime-$stime; print "$diff \n"; close(pc_log); close(pctxt); ########################################## sub thread { my $net = shift; my @ip = (1..255); my $port = 12345; my $thr0 = threads->new(\&scan, $net,@ip[0..15]); my $thr1 = threads->new(\&scan, $net,@ip[16..31]); my $thr2 = threads->new(\&scan, $net,@ip[32..47]); my $thr3 = threads->new(\&scan, $net,@ip[48..63]); my $thr4 = threads->new(\&scan, $net,@ip[64..79]); my $thr5 = threads->new(\&scan, $net,@ip[80..95]); my $thr6 = threads->new(\&scan, $net,@ip[96..111]); my $thr7 = threads->new(\&scan, $net,@ip[112..127]); my $thr8 = threads->new(\&scan, $net,@ip[128..143]); my $thr9 = threads->new(\&scan, $net,@ip[144..159]); my $thr10 = threads->new(\&scan, $net,@ip[160..175]); my $thr11 = threads->new(\&scan, $net,@ip[176..191]); my $thr12 = threads->new(\&scan, $net,@ip[192..207]); my $thr13 = threads->new(\&scan, $net,@ip[208..223]); my $thr14 = threads->new(\&scan, $net,@ip[224..239]); my $thr15 = threads->new(\&scan, $net,@ip[240..254]); $thr0->join(); $thr1->join(); $thr2->join(); $thr3->join(); $thr4->join(); $thr5->join(); $thr6->join(); $thr7->join(); $thr8->join(); $thr9->join(); $thr10->join(); $thr11->join(); $thr12->join(); $thr13->join(); $thr14->join(); $thr15->join(); } sub scan { my ($net,@ip) = @_; foreach my $ip (@ip) { $host ="$net$ip"; if (Is_Host_Alive($host)) { my $socket = new IO::Socket::INET( PeerHost =>$host, PeerPort =>'12345', Proto =>'tcp' );# or die "ERROR in Socket Creation : $!\n"; if (($socket) && scan700($host)) { print "$host not shutdown \n"; } } # $socket->close(); } } sub scan700 { my ($ip) = @_; $host = "$ip"; my $socket = new IO::Socket::INET( PeerHost =>$host, PeerPort =>'700', Proto =>'tcp' );# or die "ERROR in Socket Creation : $!\n"; if($socket) { print "$host is ATM \n"; return 0; } #$socket->close(); return 1; } sub Is_Host_Alive { my ($host) = @_; my $tmp_icmp=Net::Ping->new('icmp'); if(!$tmp_icmp->ping($host)) { #print "$host ping unreachable \n"; $tmp_icmp->close; return 0; } $tmp_icmp->close; return 1; }