line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package SysAdmin; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
33501
|
use 5.008; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
57
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.11'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#use Moose; |
9
|
1
|
|
|
1
|
|
992
|
use IO::Socket; |
|
1
|
|
|
|
|
45565
|
|
|
1
|
|
|
|
|
5
|
|
10
|
1
|
|
|
1
|
|
844
|
use Carp; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
124
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
## For SysAdmin::Date |
13
|
1
|
|
|
1
|
|
1015
|
use POSIX qw(strftime); |
|
1
|
|
|
|
|
9011
|
|
|
1
|
|
|
|
|
8
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head2 _default_socket_ports |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _check_socket { |
20
|
0
|
|
|
0
|
|
|
my ($host, $port) = @_; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my $test_port = SysAdmin::_default_socket_ports($port,"port"); |
23
|
0
|
|
|
|
|
|
my $test_proto = SysAdmin::_default_socket_ports($port,"proto"); |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my $socket_object = new IO::Socket::INET ( |
26
|
|
|
|
|
|
|
PeerAddr => "$host", |
27
|
|
|
|
|
|
|
PeerPort => "$test_port", |
28
|
|
|
|
|
|
|
Proto => "$test_proto", |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
0
|
0
|
|
|
|
|
if($socket_object){ |
32
|
0
|
|
|
|
|
|
return 1; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
else{ |
35
|
0
|
|
|
|
|
|
return 0; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 _default_socket_ports |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _default_socket_ports { |
44
|
0
|
|
|
0
|
|
|
my ($port, $proto) = @_; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my %known_port_hash = ( |
47
|
|
|
|
|
|
|
80 => { |
48
|
|
|
|
|
|
|
"port" => "80", |
49
|
|
|
|
|
|
|
"proto" => "tcp" |
50
|
|
|
|
|
|
|
}, |
51
|
|
|
|
|
|
|
5432 => { |
52
|
|
|
|
|
|
|
"port" => "5432", |
53
|
|
|
|
|
|
|
"proto" => "tcp" |
54
|
|
|
|
|
|
|
}, |
55
|
|
|
|
|
|
|
3306 => { |
56
|
|
|
|
|
|
|
"port" => "3306", |
57
|
|
|
|
|
|
|
"proto" => "tcp" |
58
|
|
|
|
|
|
|
}, |
59
|
|
|
|
|
|
|
1521 => { |
60
|
|
|
|
|
|
|
"port" => "1521", |
61
|
|
|
|
|
|
|
"proto" => "tcp" |
62
|
|
|
|
|
|
|
}, |
63
|
|
|
|
|
|
|
161 => { |
64
|
|
|
|
|
|
|
"port" => "161", |
65
|
|
|
|
|
|
|
"proto" => "udp" |
66
|
|
|
|
|
|
|
}, |
67
|
|
|
|
|
|
|
25 => { |
68
|
|
|
|
|
|
|
"port" => "23", |
69
|
|
|
|
|
|
|
"proto" => "tcp" |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
); |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
return $known_port_hash{$port}{$proto}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 generate_random_string |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _generate_random_string { |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
## Use my $random_password = &generate_random_string("8"); |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
0
|
|
|
my ($length_of_randomstring) = @_; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $random_string = undef; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my @chars=('a'..'z','A'..'Z','0'..'9','_'); |
89
|
0
|
|
|
|
|
|
foreach (1..$length_of_randomstring) { |
90
|
|
|
|
|
|
|
# rand @chars will generate a random |
91
|
|
|
|
|
|
|
# number between 0 and scalar @chars |
92
|
0
|
|
|
|
|
|
$random_string.=$chars[rand @chars]; |
93
|
|
|
|
|
|
|
} |
94
|
0
|
|
|
|
|
|
return $random_string; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
__END__ |