line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Peep::Host; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require 5.00503; |
4
|
3
|
|
|
3
|
|
18
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
107
|
|
5
|
|
|
|
|
|
|
# use warnings; # commented out for 5.005 compatibility |
6
|
3
|
|
|
3
|
|
16
|
use Carp; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
167
|
|
7
|
3
|
|
|
3
|
|
24
|
use Socket; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1918
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
3
|
|
|
3
|
|
21
|
use Net::Peep::Log; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
137
|
|
10
|
|
|
|
|
|
|
|
11
|
3
|
|
|
3
|
|
16
|
use vars qw{ @ISA %EXPORT_TAGS @EXPORT_OK @EXPORT $VERSION $AUTOLOAD @Attributes $LOGGER }; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
2296
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
14
|
|
|
|
|
|
|
%EXPORT_TAGS = ( 'all' => [ qw( ) ] ); |
15
|
|
|
|
|
|
|
@EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
16
|
|
|
|
|
|
|
@EXPORT = qw( ); |
17
|
|
|
|
|
|
|
$VERSION = do { my @r = (q$Revision: 1.4 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$LOGGER = new Net::Peep::Log; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
24
|
0
|
|
0
|
|
|
|
my $class = ref($self) || $self; |
25
|
0
|
|
|
|
|
|
my $this = {}; |
26
|
0
|
|
|
|
|
|
bless $this, $class; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
} # end sub new |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub name { |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# if the host name has been explicitly set, retrieve the set value |
33
|
|
|
|
|
|
|
# ... if not obtain the value by gethostbyaddr |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
36
|
0
|
0
|
|
|
|
|
if (@_) { |
37
|
0
|
|
|
|
|
|
$self->{'NAME'} = shift; |
38
|
|
|
|
|
|
|
} else { |
39
|
0
|
0
|
|
|
|
|
if (exists $self->{'NAME'}) { |
|
|
0
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
return $self->{'NAME'}; |
41
|
|
|
|
|
|
|
} elsif (exists $self->{'IP'}) { |
42
|
0
|
|
|
|
|
|
my $iaddr = inet_aton($self->{'IP'}); |
43
|
0
|
|
|
|
|
|
my ($name,$aliases,$addrtype,$length,@addrs) = gethostbyaddr($iaddr,AF_INET); |
44
|
0
|
0
|
|
|
|
|
return $name ? $name : undef; |
45
|
|
|
|
|
|
|
} else { |
46
|
0
|
|
|
|
|
|
confess "Cannot obtain host name: No host name or IP address has been specified."; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
} # end sub name |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub ip { |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# if the host IP address has been explicitly set, retrieve the set |
55
|
|
|
|
|
|
|
# value ... if not obtain the value by gethostbyname |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
58
|
0
|
0
|
|
|
|
|
if (@_) { |
59
|
0
|
|
|
|
|
|
$self->{'IP'} = shift; |
60
|
|
|
|
|
|
|
} else { |
61
|
0
|
0
|
|
|
|
|
if (exists $self->{'IP'}) { |
|
|
0
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
return $self->{'IP'}; |
63
|
|
|
|
|
|
|
} elsif (exists $self->{'NAME'}) { |
64
|
0
|
|
|
|
|
|
my ($name,$aliases,$addrtype,$length,@addrs) = gethostbyname($self->{'NAME'}); |
65
|
0
|
0
|
|
|
|
|
if (@addrs) { |
66
|
0
|
|
|
|
|
|
my $ip = inet_ntoa($addrs[0]); |
67
|
0
|
0
|
|
|
|
|
return $ip ? $ip : undef; |
68
|
|
|
|
|
|
|
} else { |
69
|
0
|
|
|
|
|
|
confess "Cannot obtain IP address: Could not get host by name for ".$self->{'NAME'}."."; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} else { |
72
|
0
|
|
|
|
|
|
confess "Cannot obtain IP address: No host name or IP address has been specified."; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
} # end sub ip |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub isIP { |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
81
|
0
|
|
0
|
|
|
|
my $ip = shift || confess "Hostname or IP address not found."; |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
return $ip =~ /^(\d+\.)+\d+$/ ? 1 : 0; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} # end sub isIP |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |