line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::pscan::Utils; |
2
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
4
|
1
|
|
|
1
|
|
101
|
use base qw(Exporter); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
120
|
|
5
|
1
|
|
|
1
|
|
1283
|
use Term::ANSIColor; |
|
1
|
|
|
|
|
10238
|
|
|
1
|
|
|
|
|
99
|
|
6
|
1
|
|
|
1
|
|
1172
|
use URI; |
|
1
|
|
|
|
|
9124
|
|
|
1
|
|
|
|
|
33
|
|
7
|
1
|
|
|
1
|
|
991
|
use Net::DNS::Resolver; |
|
1
|
|
|
|
|
108920
|
|
|
1
|
|
|
|
|
46
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
9
|
use constant debug => $ENV{DEBUG}; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1204
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT = qw(_debug |
12
|
|
|
|
|
|
|
info |
13
|
|
|
|
|
|
|
error |
14
|
|
|
|
|
|
|
notice |
15
|
|
|
|
|
|
|
print_list |
16
|
|
|
|
|
|
|
resolve |
17
|
|
|
|
|
|
|
generate_ports |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _debug { |
21
|
0
|
|
|
0
|
|
|
print STDERR @_, "\n" if debug; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub generate_ports { |
25
|
0
|
|
|
0
|
0
|
|
my $Port = shift; |
26
|
0
|
|
|
|
|
|
my $first; |
27
|
|
|
|
|
|
|
my $last; |
28
|
0
|
0
|
|
|
|
|
if ( $Port =~ /\*/ ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub resolve { |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
0
|
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
|
0
|
|
|
|
|
if ($query) { |
55
|
0
|
|
|
|
|
|
foreach my $rr ( $query->answer ) { |
56
|
0
|
0
|
|
|
|
|
next unless $rr->type eq "A"; |
57
|
0
|
|
|
|
|
|
return $rr->address; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
return undef; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub print_list { |
67
|
0
|
|
|
0
|
0
|
|
my @lines = @_; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $column_w = 0; |
70
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
map { $column_w = length( $_->[0] ) if length( $_->[0] ) > $column_w; } |
|
0
|
|
|
|
|
|
|
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
|
0
|
0
|
|
|
|
if ( $ENV{WRAP} |
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 ) { |
99
|
0
|
|
|
|
|
|
$cnt++; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my $c = $1; |
102
|
0
|
|
|
|
|
|
print $c; |
103
|
|
|
|
|
|
|
|
104
|
0
|
0
|
0
|
|
|
|
if ( $c =~ /[ \,]/ && $firstline && $cnt > $screen_width ) { |
|
|
0
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
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 =~ /[ \,]/ |
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
|
0
|
|
|
|
|
print "\n" if $wrapped; |
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
|
0
|
|
|
|
|
$$arg[0] = ' ' unless $$arg[0]; |
129
|
0
|
|
|
|
|
|
print join " ", @$arg; |
130
|
0
|
|
|
|
|
|
print "\n"; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub error { |
137
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
sub info { |
144
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
sub notice { |
151
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
sub dialog_yes_default { |
158
|
0
|
|
|
0
|
0
|
|
my $msg = shift; |
159
|
0
|
|
|
|
|
|
local $|; |
160
|
0
|
|
|
|
|
|
print STDERR $msg; |
161
|
0
|
|
|
|
|
|
print STDERR ' (Y/n) '; |
162
|
|
|
|
|
|
|
|
163
|
0
|
|
|
|
|
|
my $a = ; |
164
|
0
|
|
|
|
|
|
chomp $a; |
165
|
0
|
0
|
|
|
|
|
if ( $a =~ /n/ ) { |
166
|
0
|
|
|
|
|
|
return 0; |
167
|
|
|
|
|
|
|
} |
168
|
0
|
0
|
|
|
|
|
return 1 if $a =~ /y/; |
169
|
0
|
|
|
|
|
|
return 1; # default to Y |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
1; |