Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add an example directory and a script to go in it. #1

Merged
merged 1 commit into from

2 participants

@perigrin

I had a difficult time parsing out the example from the synopsis and I
had to dig into the tests. This commit adds a simple eg/ directory with
the script that I ended up writing. It uses NetAddr::IP to take a list
of CIDR blocks and ping all of the hosts.

@perigrin perigrin add an example script
I had a difficult time parsing out the example from the synopsis and I
had to dig into the tests. This commit adds a simple eg/ directory with
the script that I ended up writing. It uses NetAddr::IP to take a list
of CIDR blocks and ping all of the hosts.
bd859c7
@rcaputo rcaputo merged commit 85b6d41 into rcaputo:master
@rcaputo
Owner

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 2, 2012
  1. @perigrin

    add an example script

    perigrin authored
    I had a difficult time parsing out the example from the synopsis and I
    had to dig into the tests. This commit adds a simple eg/ directory with
    the script that I ended up writing. It uses NetAddr::IP to take a list
    of CIDR blocks and ping all of the hosts.
This page is out of date. Refresh to see the latest.
Showing with 33 additions and 0 deletions.
  1. +33 −0 eg/test-subnet.pl
View
33 eg/test-subnet.pl
@@ -0,0 +1,33 @@
+#!/usr/bin/env perl
+use strict;
+use local::lib qw(perl5);
+
+use POE;
+use POE::Component::Client::Ping ':const';
+use NetAddr::IP;
+
+my @IPs = map {
+ map { $_->addr }
+ @{ NetAddr::IP->new($_) }
+} @ARGV;
+
+POE::Component::Client::Ping->spawn( OneReply => 1 );
+
+POE::Session->create(
+ inline_states => {
+ _start => \&_start,
+ pong => \&_pong,
+ }
+);
+
+sub _start { POE::Kernel->post( 'pinger', 'ping', 'pong', $_ ) for @IPs; }
+
+sub _pong {
+ my ( $request, $response ) = @_[ ARG0, ARG1 ];
+ my $ip = sprintf '%-15.15s', $request->[REQ_ADDRESS];
+
+ # The response address is defined if this is a response.
+ print defined $response->[RES_ADDRESS] ? "$ip ok\n" : "$ip missing\n";
+}
+
+POE::Kernel->run;
Something went wrong with that request. Please try again.