Сергей Засенко

NAME

AnyEvent::Ping - ping hosts with AnyEvent

SYNOPSIS

    use AnyEvent;
    use AnyEvent::Ping;

    my $c = AnyEvent->condvar;

    my $ping = AnyEvent::Ping->new;

    $ping->ping('google.com', 1, sub {
        my $result = shift;
        print "Result: ", $result->[0][0],
          " in ", $result->[0][1], " seconds\n";
        $c->send;
    });

    $c->recv;
    $ping->end;

DESCRIPTION

AnyEvent::Ping is an asynchronous AnyEvent pinger.

ATTRIBUTES

AnyEvent::Ping implements the following attributes.

interval

    my $interval = $ping->interval;
    $ping->interval(1);

Interval between pings, defaults to 0.2 seconds.

timeout

    my $timeout = $ping->timeout;
    $ping->timeout(3);

Maximum response time, defaults to 5 seconds.

error

    my $error = $ping->error;

Last error message.

METHODS

AnyEvent::Ping implements the following methods.

new

    my $ping = AnyEvent::Ping->new(%options)

Constructs AnyEvent::Ping object. Following options can be passed:

interval

timeout

on_prepare

In some cases you need to "tune" the socket before it is used to ping (for exmaple, to bind it on a given IP address).

    my $ping = AnyEvent::Ping->new(
        on_prepare => sub {
            my $socket = shift;
            ...
    });

packet_generator

Generates the data to be sent.

    my $ping = AnyEvent::Ping->new(
        packet_generator => sub {
            &AnyEvent::Ping::generate_data_random($packet_size);
    });

packet_size

You can set the number of data bytes to be sent, if packet generation function is not set. The default is 54, which translates into 64 ICMP data bytes when combined with the 8 bytes of ICMP header data.

    my $ping = AnyEvent::Ping->new(packet_size => 54);

Each packet will be generated with generate_data_random() like this:

    &AnyEvent::Ping::generate_data_random($packet_size);

ping

    $ping->ping($ip, $n => sub {
        my $result = shift;
    });

Perform a ping of a given $ip address $n times.

end

    $ping->end;

Ends all pings and releases resources.

SEE ALSO

AnyEvent, AnyEvent::FastPing

AUTHOR

Sergey Zasenko, undef@cpan.org.

CREDITS

Kirill (qsimpleq)

COPYRIGHT AND LICENSE

Copyright (C) 2012-2014, Sergey Zasenko

This program is free software, you can redistribute it and/or modify it under the same terms as Perl 5.12.




Hosting generously
sponsored by Bytemark