| 1 | #!/usr/bin/env perl | ||
| 2 | use AnyEvent; | ||
| 3 | use AnyEvent::Ping; | ||
| 4 | |||
| 5 | my $host = shift || '4.2.2.2'; | ||
| 6 | my $times = shift || 4; | ||
| 7 | my $package_s = shift || 56; | ||
| 8 | my $c = AnyEvent->condvar; | ||
| 9 | |||
| 10 | my $ping = AnyEvent::Ping->new; | ||
| 11 | |||
| 12 | print "PING $host $package_s(@{[$package_s+8]}) bytes of data\n"; | ||
| 13 | $ping->ping($host, $times, sub { | ||
| 14 | my $results = shift; | ||
| 15 | foreach my $result (@$results) { | ||
| 16 | my $status = $result->[0]; | ||
| 17 | my $time = $result->[1]; | ||
| 18 | printf "%s from %s: time=%f ms\n", | ||
| 19 | $status, $host, $time * 1000; | ||
| 20 | }; | ||
| 21 | $c->send; | ||
| 22 | }); | ||
| 23 | |||
| 24 | $c->recv; | ||
| 25 | $ping->end; |