line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package IPGen::V4; |
2
|
1
|
|
|
1
|
|
6155
|
use 5.005; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
33
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
58
|
|
4
|
|
|
|
|
|
|
require Exporter; |
5
|
1
|
|
|
1
|
|
855
|
use AutoLoader qw(AUTOLOAD); |
|
1
|
|
|
|
|
1515
|
|
|
1
|
|
|
|
|
7
|
|
6
|
1
|
|
|
1
|
|
28
|
use vars qw($VERSION @ISA @EXPORT); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
478
|
|
7
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
8
|
|
|
|
|
|
|
@EXPORT = qw( ipgen ); |
9
|
|
|
|
|
|
|
$VERSION = '1.1'; |
10
|
|
|
|
|
|
|
sub new{ |
11
|
0
|
|
|
0
|
0
|
|
my $self = bless {}, shift; |
12
|
0
|
|
|
|
|
|
$self->{range} = shift; |
13
|
0
|
|
|
|
|
|
$self; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
sub ipgen{ |
16
|
0
|
|
|
0
|
0
|
|
my($range); |
17
|
0
|
0
|
|
|
|
|
$range = ref($_[0])?$_[0]->{range}:$_[0]; |
18
|
0
|
0
|
|
|
|
|
if($range =~ /^((\d{1,3}\.){3}\d{1,3})\/(\d{1,2})$/) #ipv4/block |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
19
|
|
|
|
|
|
|
{ |
20
|
0
|
|
|
|
|
|
my $from = oct("0b".substr(join("",map substr(unpack("B32",pack("N",$_)),-8),split(/\./,$1)),0,$3)."0"x(32-$3)); |
21
|
0
|
|
|
|
|
|
join '.', unpack 'C4', pack 'N', $from + int rand (oct("0b".substr(join("",map substr(unpack("B32",pack("N",$_)),-8),split(/\./,$1)),0,$3)."1"x(32-$3)) - $from); |
22
|
|
|
|
|
|
|
}elsif($range =~ /^((\d{1,3}\.){3}\d{1,3})-((\d{1,3}\.){3}\d{1,3})$/) #ipv4-ipv4(full-range) |
23
|
|
|
|
|
|
|
{ |
24
|
0
|
|
|
|
|
|
my $from = (unpack N => pack CCCC => split /\./ => $1); |
25
|
0
|
|
|
|
|
|
join '.', unpack 'C4', pack 'N', $from + int rand ((unpack N => pack CCCC => split /\./ => $3) - $from); |
26
|
|
|
|
|
|
|
}elsif($range =~ /^(\d{1,3})-?(\d{1,3})?\.(\d{1,3})-?(\d{1,3})?\.(\d{1,3})-?(\d{1,3})?\.(\d{1,3})-?(\d{1,3})?$/) #byte1.1-byte1.2...(sub-range) |
27
|
|
|
|
|
|
|
{ |
28
|
0
|
|
|
|
|
|
($1+int rand abs $2-$1+1).'.'.($3+int rand abs $4-$3+1).'.'.($5+int rand abs $6-$5+1).'.'.($7+int rand abs $8-$7+1); |
29
|
|
|
|
|
|
|
}elsif(!length $range){ |
30
|
0
|
|
|
|
|
|
join '.', unpack 'C4', pack 'N',int rand 42949672951; # = 255.255.255.255 |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |
35
|
|
|
|
|
|
|
__END__ |