use Intel::AMT::NetworkAdministration;
use Data::Dump qw/dump/;
use Regexp::Common qw/net/;
-use Net::Ping;
use html;
+use ping;
use CouchDB;
sub info {
$ip ||= $client_ip;
- my $p = Net::Ping->new;
-
- if ( ! $p->ping( $ip, 0.7 ) ) {
+ if ( ! ping::host( $ip ) ) {
return "$ip unreachable";
}
use autodie;
use File::Slurp;
-use Net::Ping;
use Data::Dump qw/dump/;
use server;
use format;
use ip;
+use ping;
our $debug = $server::debug;
my $mac = shift;
$mac = format::mac($mac);
- my $p = Net::Ping->new;
-
my $prefix = $server::ip;
$prefix =~ s{\.\d+$}{.};
my $addr = $server::ip_from || die;
my $ip = $prefix . $addr;
- while ( -e ip_path($ip) || $p->ping( $ip, 0.7 ) ) {
+ while ( -e ip_path($ip) || ping::host($ip) ) {
$ip = $prefix . $addr++;
die "all addresses allocated!" if $addr == $server::ip_to;
warn "skip $ip\n";
} else {
- my $arp = clinet::arp_mac_dev;
+ my $arp = client::arp_mac_dev;
+ my @ips = client::all_ips;
+
+ my $ping;
+ $ping = ping::fping( @ips ) if $param->{ping};
print $client ok
, qq|<h2>Clients on $server::ip</h2>|
my $ip = $_;
my $conf = client::all_conf( $ip );
my $mac = delete $conf->{mac} || '';
+ my $style;
+ $style
+ = 'style="color:'
+ . ( $ping->{$ip} ? 'green' : 'red' )
+ . '"'
+ if $ping;
(
- qq|<a name=$ip href=/client/$ip>$ip</a>|
+ qq|<a $style name=$ip href=/client/$ip>$ip</a>|
, format::mac( $mac => 'html' )
, $arp->{$mac}
, delete $conf->{hostname}
, delete $conf->{deploy}
, ( %$conf ? html::pre_dump( $conf ) : qq|<a href=/nmap?scan=$ip>nmap</a>| )
);
- } client::all_ips
+ } @ips
)
;
+ print $client qq|
+ <form method=get>
+ <input type=submit name=ping value=ping>
+ </form>
+ |;
}
} elsif ( $path =~ m{^/brctl} ) {
print $client ok
--- /dev/null
+package ping;
+
+use warnings;
+use strict;
+
+use Net::Ping;
+use Data::Dump qw/dump/;
+use Time::HiRes;
+
+sub host {
+ Net::Ping->new->ping( shift, 0.7 );
+}
+
+sub fping {
+ my $p = Net::Ping->new('syn', 0.3);
+ $p->hires;
+
+ my $status;
+ my %syn;
+
+ foreach my $host ( @_ ) {
+ my ($ret,$nslookup_duration,$ip) = $p->ping($host);
+
+ if ( $ret ) {
+ $syn{$host} = $ip;
+# $status->{dns}->{$ip} = $nslookup_duration * 1000;
+ } else {
+ push @{ $status->{address_not_found} }, $host;
+ }
+ }
+
+ while (my ($host,$rtt,$ip) = $p->ack) {
+ $status->{$ip}->{rtt} = $rtt * 1000; # ms
+ }
+
+ warn dump($status);
+
+ return $status;
+
+}
+
+1;
--- /dev/null
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+use autodie;
+
+use Test::More tests => 3;
+
+use_ok 'ping';
+
+ok( ping::host( 'localhost' ), 'ping' );
+
+ok( ping::fping( qw/localhost 127.0.0.1 192.168.1.1 172.16.10.1/ ), 'fping' );
+