line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id: Target.pm,v 1.6 2006/11/21 20:13:39 gomor Exp $ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
package Net::Packet::Target; |
5
|
1
|
|
|
1
|
|
10211
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
82
|
|
6
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
479
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.01'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Class::Gomor::Array; |
11
|
|
|
|
|
|
|
our @ISA = qw(Class::Gomor::Array); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @AS = qw( |
14
|
|
|
|
|
|
|
mac |
15
|
|
|
|
|
|
|
port |
16
|
|
|
|
|
|
|
protocol |
17
|
|
|
|
|
|
|
hostname |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
our @AA = qw( |
20
|
|
|
|
|
|
|
ipList |
21
|
|
|
|
|
|
|
portList |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
our @AO = qw( |
24
|
|
|
|
|
|
|
ip |
25
|
|
|
|
|
|
|
ip6 |
26
|
|
|
|
|
|
|
ipRange |
27
|
|
|
|
|
|
|
portRange |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
__PACKAGE__->cgBuildIndices; |
30
|
|
|
|
|
|
|
__PACKAGE__->cgBuildAccessorsScalar(\@AS); |
31
|
|
|
|
|
|
|
__PACKAGE__->cgBuildAccessorsArray (\@AA); |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
1
|
|
6
|
no strict 'vars'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
111
|
|
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
use Net::Packet::Utils qw(explodeIps explodePorts getHostIpv4Addr |
36
|
1
|
|
|
1
|
|
2968
|
getHostIpv6Addr); |
|
0
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub ip { |
39
|
|
|
|
|
|
|
my $self = shift; |
40
|
|
|
|
|
|
|
@_ ? do { $self->[$__ip] = getHostIpv4Addr(shift()) } |
41
|
|
|
|
|
|
|
: $self->[$__ip]; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub ip6 { |
45
|
|
|
|
|
|
|
my $self = shift; |
46
|
|
|
|
|
|
|
@_ ? do { $self->[$__ip6] = getHostIpv6Addr(shift()) } |
47
|
|
|
|
|
|
|
: $self->[$__ip6]; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub new { |
51
|
|
|
|
|
|
|
my $self = shift->SUPER::new( |
52
|
|
|
|
|
|
|
ipList => [], |
53
|
|
|
|
|
|
|
portList => [], |
54
|
|
|
|
|
|
|
@_, |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
if ($self->ip) { |
58
|
|
|
|
|
|
|
$self->ip(getHostIpv4Addr($self->ip)); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
if ($self->ip6) { |
61
|
|
|
|
|
|
|
$self->ip6(getHostIpv6Addr($self->ip6)); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$self; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub ipRange { |
68
|
|
|
|
|
|
|
my $self = shift; |
69
|
|
|
|
|
|
|
if (@_) { |
70
|
|
|
|
|
|
|
$self->[$__ipRange] = shift; |
71
|
|
|
|
|
|
|
$self->ipList([ explodeIps($self->[$__ipRange]) ]); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
$self->[$__ipRange]; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub portRange { |
77
|
|
|
|
|
|
|
my $self = shift; |
78
|
|
|
|
|
|
|
if (@_) { |
79
|
|
|
|
|
|
|
$self->[$__portRange] = shift; |
80
|
|
|
|
|
|
|
$self->portList([ explodePorts($self->[$__portRange]) ]); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
$self->[$__portRange]; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub isMultiple { |
86
|
|
|
|
|
|
|
my $self = shift; |
87
|
|
|
|
|
|
|
($self->ipRange || $self->portRange) ? 1 : 0; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 NAME |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Net::Packet::Target - an object for all network related stuff |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 SYNOPSIS |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
use Net::Packet::Target; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# Create multiple targets, with multiple port |
101
|
|
|
|
|
|
|
my $t1 = Net::Packet::Target->new; |
102
|
|
|
|
|
|
|
$t1->ip('www.google.com'); |
103
|
|
|
|
|
|
|
$t1->portRange('21,22,25,70-90'); |
104
|
|
|
|
|
|
|
$t1->protocol('tcp'); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
print $t1->isMultiple."\n"; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
for my $port ($t1->portList) { |
109
|
|
|
|
|
|
|
print $t1->ip.' do stuff for port '.$port."\n"; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# Create multiple targets, with only one port |
113
|
|
|
|
|
|
|
my $t2 = Net::Packet::Target->new; |
114
|
|
|
|
|
|
|
$t2->ipRange('127.0.0.1-10'); |
115
|
|
|
|
|
|
|
$t2->port(22); |
116
|
|
|
|
|
|
|
$t2->protocol('tcp'); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
print $t2->isMultiple."\n"; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
for my $ip ($t2->ipList) { |
121
|
|
|
|
|
|
|
print $t2->port.'/'.$t2->protocol.' do stuff for IPv4 '.$ip."\n"; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# Create a single target |
125
|
|
|
|
|
|
|
my $t3 = Net::Packet::Target->new; |
126
|
|
|
|
|
|
|
$t3->ip('127.0.0.1'); |
127
|
|
|
|
|
|
|
$t3->port(22); |
128
|
|
|
|
|
|
|
$t3->protocol('tcp'); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
print $t3->isMultiple."\n"; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
print $t3->port.':'.$t3->protocol.' do stuff for IPv4 '.$t3->ip."\n"; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 DESCRIPTION |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
A B object can be used to describe one target, or multiple targets. They are mainly used when you use some automated tasks you which to use on a range of IPs/ports. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
To describe multiple targets, you simply enter an IP range, or a port range, or the two. To describe a single target, you enter one IP address, and one port. You can also avoid totally ports, or avoid totally IPs, you do what you want. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
It also handles IP name resolution for IPv4 and IPv6, if available. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=over 4 |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item B [ (scalar) ] |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item B [ (scalar) ] |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item B [ (scalar) ] |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item B [ (scalar) ] |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
These 4 attributes store respectively the target mac address, port, protocol to use for port, and the hostname. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item B [ (arrayref) ] |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item B [ (arrayref) ] |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
These 3 attributes store respectively an IPv4 address list, an IPv6 address list, and a port list. All this as array references. When called without parameter, they return an array. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=back |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 METHODS |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=over 4 |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item B |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Object constructor. There are no default values, due to the nature of this object. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item B |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Because a B object can be used to describe one target, or multiple ones, we must have a way to know that. This method is used to answer the question. Returns 1 if the object is composed of either multiple IPs, or multiple ports, 0 otherwise. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item B [ (scalar) ] |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Will take as a parameter an IPv4 address, or a hostname. Without argument, returns the stored value. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item B [ (scalar) ] |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Same as previous, for IPv6. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item B [ (scalar) ] |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Will take as a parameter an IPv4 address range. The format is for example: 127.0.0.1-254, or 127.0-10.1.50-70. It will store the result in B attribute, to be easily used in a B loop. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item B [ (scalar) ] |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Same as previous, but for port ranges. The format is for example: 1-1024, 500-600,100-110. It will store the result in B attribute, to be easily used ina B loop. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=back |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=head1 SEE ALSO |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
L |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head1 AUTHOR |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Patrice EGomoRE Auffret |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Copyright (c) 2006, Patrice EGomoRE Auffret |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
You may distribute this module under the terms of the Artistic license. |
207
|
|
|
|
|
|
|
See LICENSE.Artistic file in the source distribution archive. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=cut |