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;

In reply to Optimized remote ping by themonk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.