/[pxelator]/lib/PXElator/ping.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /lib/PXElator/ping.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 334 - (hide annotations)
Fri Aug 28 23:30:38 2009 UTC (14 years, 7 months ago) by dpavlin
File size: 739 byte(s)
cleanup client detection (again), added ping to single host

1 dpavlin 330 package ping;
2    
3     use warnings;
4     use strict;
5    
6     use Net::Ping;
7     use Data::Dump qw/dump/;
8     use Time::HiRes;
9 dpavlin 332 use client;
10 dpavlin 330
11     sub host {
12     Net::Ping->new->ping( shift, 0.7 );
13     }
14    
15     sub fping {
16     my $p = Net::Ping->new('syn', 0.3);
17     $p->hires;
18    
19     my $status;
20     my %syn;
21    
22     foreach my $host ( @_ ) {
23     my ($ret,$nslookup_duration,$ip) = $p->ping($host);
24    
25     if ( $ret ) {
26     $syn{$host} = $ip;
27     # $status->{dns}->{$ip} = $nslookup_duration * 1000;
28     } else {
29     push @{ $status->{address_not_found} }, $host;
30     }
31     }
32    
33     while (my ($host,$rtt,$ip) = $p->ack) {
34     $status->{$ip}->{rtt} = $rtt * 1000; # ms
35 dpavlin 331 warn "# $host $rtt $ip\n";
36     client::conf( $ip => 'hostname', default => $host ) if $host ne $ip;
37 dpavlin 330 }
38    
39 dpavlin 334 warn "# fping ",dump($status);
40 dpavlin 330
41     return $status;
42    
43     }
44    
45     1;

  ViewVC Help
Powered by ViewVC 1.1.26