| 1 | package App::pscan::Utils; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use base qw(Exporter); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Term::ANSIColor; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use URI; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Net::DNS::Resolver; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use constant debug => $ENV{DEBUG}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | our @EXPORT = qw(_debug | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | info | ||||||||||||||||||||||||||||||||||||||||||||||
| 13 | error | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | notice | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | print_list | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | resolve | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | generate_ports | ||||||||||||||||||||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub _debug { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_debug: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | print STDERR @_, "\n" if debug; | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub generate_ports { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_ports: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | my $Port = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | my $first; | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | my $last; | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | if ( $Port =~ /\*/ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | $first = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | $last = 65536; | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | elsif ( $Port =~ /\-/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ( $first, $last ) = split( /\-/, $Port ); | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | elsif ( !defined($Port) ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | $first = $last = 80; | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $first = $last = $Port; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | return ( $first, $last ); | |||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub resolve { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resolve: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $IP = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my $ResolvedIP; | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my $res = Net::DNS::Resolver->new( nameservers => [qw(8.8.8.8)] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $query = $res->search($IP); | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ($query) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | foreach my $rr ( $query->answer ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | next unless $rr->type eq "A"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | return $rr->address; | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | sub print_list { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_list: not called CC=14 SCAR=53.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | my @lines = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my $column_w = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | map { $column_w = length( $_->[0] ) if length( $_->[0] ) > $column_w; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | @lines; | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my $screen_width = 92; | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | for my $arg (@lines) { | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $title = shift @$arg; | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my $padding = int($column_w) - length($title); | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | if ( $ENV{WRAP} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ENV{"WRAP"} and $column_w + 3 + length(join " ", @$arg) > $screen_width
MC/DC0%0/2
$ENV{"WRAP"} and $column_w + 3 + length(join " ", @$arg) > $screen_width
$ENV{"WRAP"}
$column_w + 3 + length(join " ", @$arg) > $screen_width
Truth table0%0/3
A and B
A= $ENV{"WRAP"}B= $column_w + 3 + length(join " ", @$arg) > $screen_width
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | && ( $column_w + 3 + length( join( " ", @$arg ) ) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | > $screen_width ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # wrap description | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | my $string | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | = color('bold') | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | . $title | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | . color('reset') | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | . " " x $padding . " - " | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | . join( " ", @$arg ) . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $string =~ s/\n//g; | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my $cnt = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my $firstline = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my $tab = 4; | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $wrapped = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | while ( $string =~ /(.)/g ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $cnt++; | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my $c = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | print $c; | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if ( $c =~ /[ \,]/ && $firstline && $cnt > $screen_width ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/6
$c =~ /[ \,]/ and $firstline and $cnt > $screen_width
$c =~ /[ \,]/ and $firstline
MC/DC0%0/3
$c =~ /[ \,]/ and $firstline and $cnt > $screen_width
$c =~ /[ \,]/
$firstline
$cnt > $screen_width
Truth table0%0/4
A and B and C
A= $c =~ /[ \,]/B= $firstlineC= $cnt > $screen_width
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | print "\n" . " " x ( $column_w + 3 + $tab ); | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $firstline = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $cnt = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | $wrapped = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | ▶ | elsif ($c =~ /[ \,]/ | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$c =~ /[ \,]/ and not $firstline and $cnt > $screen_width - $column_w
$c =~ /[ \,]/ and not $firstline
MC/DC0%0/3
$c =~ /[ \,]/ and not $firstline and $cnt > $screen_width - $column_w
$c =~ /[ \,]/
not $firstline
$cnt > $screen_width - $column_w
Truth table0%0/4
A and not(B) and C
A= $c =~ /[ \,]/B= not $firstlineC= $cnt > $screen_width - $column_w
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | && !$firstline | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | && $cnt > ( $screen_width - $column_w ) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | print "\n" . " " x ( $column_w + 3 + $tab ); | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | $cnt = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | $wrapped = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | print "\n" if $wrapped; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | print color 'bold'; | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | print $title; | |||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | print color 'reset'; | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | print " " x $padding; | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | print " - "; | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | $$arg[0] = ' ' unless $$arg[0]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | print join " ", @$arg; | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | sub error { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my @msg = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | print STDERR color 'red'; | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | print STDERR join( "\n", @msg ), "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | print STDERR color 'reset'; | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | sub info { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
info: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | my @msg = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | print STDERR color 'green'; | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | print STDERR join( "\n", @msg ), "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | print STDERR color 'reset'; | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | sub notice { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
notice: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | my @msg = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | print STDERR color 'bold yellow'; | |||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | print STDERR join( "\n", @msg ), "\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | print STDERR color 'reset'; | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | sub dialog_yes_default { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dialog_yes_default: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | my $msg = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | local $|; | |||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | print STDERR $msg; | |||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | print STDERR ' (Y/n) '; | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | my $a = <STDIN>; | |||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | chomp $a; | |||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | if ( $a =~ /n/ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | return 1 if $a =~ /y/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | return 1; # default to Y | |||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||