themonk has asked for the wisdom of the Perl Monks concerning the following question:
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.
***************************AnyEvent Code******************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"; } }
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;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Optimized remote ping (syn/ack)
by BrowserUk (Patriarch) on Jul 17, 2015 at 11:40 UTC | |
by themonk (Acolyte) on Jul 17, 2015 at 18:06 UTC | |
by themonk (Acolyte) on Jul 17, 2015 at 18:45 UTC | |
by BrowserUk (Patriarch) on Jul 17, 2015 at 19:05 UTC | |
by themonk (Acolyte) on Jul 17, 2015 at 19:49 UTC | |
| |
Re: Optimized remote ping
by afoken (Chancellor) on Jul 17, 2015 at 08:47 UTC | |
Re: Optimized remote ping
by QM (Parson) on Jul 17, 2015 at 09:13 UTC | |
Re: Optimized remote ping
by shmem (Chancellor) on Jul 17, 2015 at 09:37 UTC | |
by Anonymous Monk on Jul 17, 2015 at 11:20 UTC | |
Re: Optimized remote ping
by Anonymous Monk on Jul 19, 2015 at 23:01 UTC | |
Re: Optimized remote ping
by thargas (Deacon) on Jul 20, 2015 at 13:33 UTC | |
Re: Optimized remote ping
by phillipo (Novice) on Sep 03, 2015 at 14:16 UTC | |
A reply falls below the community's threshold of quality. You may see it by logging in. |
Back to
Seekers of Perl Wisdom