Hi,
Problem statement: Ping 1000 hosts on port 80, protocol:TCP.
Framework: Mojolicious
For 1000 hosts i could optimize(duhh!!!) to get results in around 1000secs(16 mins).Which is not so good.
I tried below modules,
1) Net::Ping(tried default and also tcp).
2) AnyEvent;
3) AnyEvent::Ping
4)AnyEvent::Socket
5) AnyEvent::Ping::TCP
6) Mojo::IOLoop
can anyone please point me out to a better approach.
Sample code below of Net::Ping.
use Net::Ping;
my $p;
$p = Net::Ping->new('tcp',1);
my $port = '3000';
$p->port_number($port);
my $timeout = 10;
my @ip = ('192.168.0.1','127.0.0.1','19.208.226.252','46.9.118.111','5
+7.88.211.216','99.142.126.191','57.226.26.163','205.48.22.171','225.2
+35.31.150','232.169.84.210',
'93.239.247.55','151.242.150.119','15.74.220.132','58.230.90.160','219
+.186.233.148',
'192.188.162.6','127.0.0.1');
foreach (@ip){
if ($p->ping("$_")){
print "$_ is alive.\n"
}
else{
print "$_ is not alive \n";
}
}
***************************AnyEvent Code******************
use AnyEvent;
use AnyEvent::Ping;
my $c = AnyEvent->condvar;
my @ip = ('192.168.0.1','127.0.0.1','19.208.226.252','46.9.118.111','5
+7.88.211.216','99.142.126.191','57.226.26.163','205.48.22.171','225.2
+35.31.150','232.169.84.210',
'93.239.247.55','151.242.150.119','15.74.220.132','58.230.90.160','219
+.186.233.148',
'192.188.162.6','127.0.0.1');
my $ping = AnyEvent::Ping->new();
foreach (@ip){
$ping->ping($_, 1, sub {
my $result = shift;
print "$_ Result: ", $result->[0][0],
" in ", $result->[0][1], " seconds\n";
$c->send;
});
}
$c->recv;