/[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 331 - (hide annotations)
Fri Aug 28 22:36:06 2009 UTC (14 years, 8 months ago) by dpavlin
File size: 716 byte(s)
fill-in hostnames from dns

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    
10     sub host {
11     Net::Ping->new->ping( shift, 0.7 );
12     }
13    
14     sub fping {
15     my $p = Net::Ping->new('syn', 0.3);
16     $p->hires;
17    
18     my $status;
19     my %syn;
20    
21     foreach my $host ( @_ ) {
22     my ($ret,$nslookup_duration,$ip) = $p->ping($host);
23    
24     if ( $ret ) {
25     $syn{$host} = $ip;
26     # $status->{dns}->{$ip} = $nslookup_duration * 1000;
27     } else {
28     push @{ $status->{address_not_found} }, $host;
29     }
30     }
31    
32     while (my ($host,$rtt,$ip) = $p->ack) {
33     $status->{$ip}->{rtt} = $rtt * 1000; # ms
34 dpavlin 331 warn "# $host $rtt $ip\n";
35     client::conf( $ip => 'hostname', default => $host ) if $host ne $ip;
36 dpavlin 330 }
37    
38     warn dump($status);
39    
40     return $status;
41    
42     }
43    
44     1;

  ViewVC Help
Powered by ViewVC 1.1.26