line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::GrpNetworks; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
987
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
4
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
1479
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
@ISA = qw(Exporter AutoLoader); |
9
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
10
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
11
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
12
|
|
|
|
|
|
|
@EXPORT = qw( |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
$VERSION = '1.08'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Preloaded methods go here. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new |
20
|
|
|
|
|
|
|
{ |
21
|
1
|
|
|
1
|
0
|
78
|
my $class = shift; |
22
|
1
|
|
|
|
|
11
|
my $GrpNet = {}; |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
|
|
3
|
bless $GrpNet, $class; |
25
|
1
|
|
|
|
|
4
|
return $GrpNet; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub find |
29
|
|
|
|
|
|
|
{ |
30
|
1
|
|
|
1
|
0
|
33
|
my ($obj, $ip) = @_; |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
3
|
my($ret, $first, $middle, $last, $int_ip); |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
2
|
$first = 0; |
35
|
1
|
|
|
|
|
1
|
$last = $#{$obj->{'Net'}}; |
|
1
|
|
|
|
|
3
|
|
36
|
1
|
|
|
|
|
2
|
$int_ip = ip2int($ip); |
37
|
1
|
|
66
|
|
|
19
|
while ( $last >= $first and $ret eq '' ) |
38
|
|
|
|
|
|
|
{ |
39
|
2
|
|
|
|
|
5
|
$middle = int(($last + $first)/2); |
40
|
2
|
100
|
|
|
|
14
|
if ( $obj->{'Net'}[$middle]{'Network'} <= $int_ip ) # May be the correct network |
41
|
|
|
|
|
|
|
{ |
42
|
1
|
50
|
|
|
|
5
|
if ( ($int_ip & $obj->{'Net'}[$middle]{'Mask'}) == $obj->{'Net'}[$middle]{'Network'} ) |
43
|
|
|
|
|
|
|
{ |
44
|
1
|
|
|
|
|
3
|
$ret = $obj->{'Net'}[$middle]{'Name'}; |
45
|
|
|
|
|
|
|
} |
46
|
1
|
|
|
|
|
4
|
$first = $middle + 1; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else |
49
|
|
|
|
|
|
|
{ |
50
|
1
|
|
|
|
|
6
|
$last = $middle - 1; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
} |
53
|
1
|
|
|
|
|
4
|
return($ret); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub print |
59
|
|
|
|
|
|
|
{ |
60
|
0
|
|
|
0
|
0
|
0
|
my ($obj) = @_; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
my $status = 0; # FALSE |
63
|
0
|
|
|
|
|
0
|
my ($ref, $name, $network, $mask); |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
0
|
foreach $ref ( @{$obj->{'Net'}} ) |
|
0
|
|
|
|
|
0
|
|
66
|
|
|
|
|
|
|
{ |
67
|
0
|
|
|
|
|
0
|
$name = $ref->{'Name'}; |
68
|
0
|
|
|
|
|
0
|
$network = int2ip($ref->{'Network'}); |
69
|
0
|
|
|
|
|
0
|
$mask = int2ip($ref->{'Mask'}); |
70
|
0
|
|
|
|
|
0
|
print "Name: $name - Net: $network - Mask: $mask\n"; |
71
|
0
|
|
|
|
|
0
|
$status = 1; # TRUE |
72
|
|
|
|
|
|
|
} |
73
|
0
|
|
|
|
|
0
|
return($status); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub add |
78
|
|
|
|
|
|
|
{ |
79
|
3
|
|
|
3
|
0
|
85
|
my ($obj, $grp_name, $net, $mask) = @_; |
80
|
|
|
|
|
|
|
|
81
|
3
|
|
|
|
|
3
|
my($status, @table); |
82
|
|
|
|
|
|
|
|
83
|
3
|
|
|
|
|
5
|
$status = 0; # FALSE |
84
|
|
|
|
|
|
|
|
85
|
3
|
50
|
33
|
|
|
6
|
if ( verif_ip_is_ok($net) and verif_ip_is_ok($mask) ) |
86
|
|
|
|
|
|
|
{ |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# |
89
|
|
|
|
|
|
|
# INCLUDE A NEW ITEN |
90
|
|
|
|
|
|
|
# |
91
|
3
|
|
|
|
|
4
|
push @{$obj->{'Net'}}, {'Name' => "$grp_name", |
|
3
|
|
|
|
|
23
|
|
92
|
|
|
|
|
|
|
'Network' => ip2int($net), |
93
|
|
|
|
|
|
|
'Mask' => ip2int($mask)}; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# |
96
|
|
|
|
|
|
|
# SORT THE TABLE OF NETWORK |
97
|
|
|
|
|
|
|
# |
98
|
3
|
|
|
|
|
7
|
@table = sort { $a->{'Network'} <=> $b->{'Network'} } @{$obj->{'Net'}}; |
|
4
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
14
|
|
99
|
3
|
|
|
|
|
6
|
$obj->{'Net'} = \@table; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
3
|
|
|
|
|
7
|
$status = 1; # TRUE |
103
|
|
|
|
|
|
|
} |
104
|
3
|
|
|
|
|
10
|
return($status); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub verif_ip_is_ok |
109
|
|
|
|
|
|
|
{ |
110
|
6
|
|
|
6
|
0
|
8
|
my($ip) = @_; |
111
|
|
|
|
|
|
|
|
112
|
6
|
|
|
|
|
9
|
my $status = 0; # FALSE |
113
|
|
|
|
|
|
|
|
114
|
6
|
50
|
|
|
|
33
|
if ( $ip =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/ ) |
115
|
|
|
|
|
|
|
{ |
116
|
6
|
50
|
33
|
|
|
125
|
if ( $1 >= 0 and $1 <= 255 and |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
117
|
|
|
|
|
|
|
$2 >= 0 and $2 <= 255 and |
118
|
|
|
|
|
|
|
$3 >= 0 and $3 <= 255 and |
119
|
|
|
|
|
|
|
$4 >= 0 and $4 <= 255 ) # IP is OK |
120
|
|
|
|
|
|
|
{ |
121
|
6
|
|
|
|
|
8
|
$status = 1; # TRUE |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
6
|
|
|
|
|
25
|
return($status); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub ip2int |
128
|
|
|
|
|
|
|
{ |
129
|
7
|
|
|
7
|
0
|
10
|
my($ip) = @_; |
130
|
7
|
|
|
|
|
9
|
my $int=0; |
131
|
7
|
|
|
|
|
9
|
my($ip1,$ip2,$ip3,$ip4); |
132
|
|
|
|
|
|
|
|
133
|
7
|
50
|
|
|
|
31
|
if ( $ip =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/ ) |
134
|
|
|
|
|
|
|
{ |
135
|
7
|
|
|
|
|
26
|
$int = ($1 * 16777216) + ($2 * 65536) + ($3 * 256) + $4; |
136
|
|
|
|
|
|
|
} |
137
|
7
|
|
|
|
|
25
|
return($int); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub int2ip |
141
|
|
|
|
|
|
|
{ |
142
|
0
|
|
|
0
|
0
|
|
my($int) = @_; |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
my($ip1, $ip2, $ip3, $ip4); |
145
|
0
|
|
|
|
|
|
my $ip = ''; |
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
$ip1 = int($int/16777216); |
148
|
0
|
|
|
|
|
|
$ip2 = int(($int & 16711680)/65536); |
149
|
0
|
|
|
|
|
|
$ip3 = int(($int & 65280)/256); |
150
|
0
|
|
|
|
|
|
$ip4 = $int & 255; |
151
|
0
|
|
|
|
|
|
$ip = "$ip1.$ip2.$ip3.$ip4"; |
152
|
0
|
|
|
|
|
|
return($ip); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
# Autoload methods go after =cut, and are processed by the autosplit program. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
1; |
159
|
|
|
|
|
|
|
__END__ |