| 1 | package IPGen::V4; | ||||||||||||||||||||||
| 2 | 1 | ▶ | use 5.005; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | 1 | require Exporter; | |||||||||||||||||||||
| 5 | 1 | ▶ | use AutoLoader qw(AUTOLOAD); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 6 | 1 | ▶ | use vars qw($VERSION @ISA @EXPORT); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 7 | 1 | @ISA = qw(Exporter); | |||||||||||||||||||||
| 8 | 1 | @EXPORT = qw( ipgen ); | |||||||||||||||||||||
| 9 | 1 | $VERSION = '1.1'; | |||||||||||||||||||||
| 10 | 0 | ▶ | sub new{ | ||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 11 | 0 | my $self = bless {}, shift; | |||||||||||||||||||||
| 12 | 0 | $self->{range} = shift; | |||||||||||||||||||||
| 13 | 0 | $self; | |||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||
| 15 | 0 | ▶ | sub ipgen{ | ||||||||||||||||||||
|
Subroutine
ipgen: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||
| 16 | 0 | my($range); | |||||||||||||||||||||
| 17 | 0 | ▶ | $range = ref($_[0])?$_[0]->{range}:$_[0]; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 18 | 0 | ▶ | if($range =~ /^((\d{1,3}\.){3}\d{1,3})\/(\d{1,2})$/) #ipv4/block | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 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 | 1; | |||||||||||||||||||||
| 35 | __END__ | ||||||||||||||||||||||