line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Rex::Commands::SimpleCheck - Simple tcp/alive checks |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 DESCRIPTION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
With this module you can do simple tcp/alive checks. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Version <= 1.0: All these functions will not be reported. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
All these functions are not idempotent. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
if(is_port_open($remote_host, $port)) { |
20
|
|
|
|
|
|
|
print "Port $port is open\n"; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 EXPORTED FUNCTIONS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
package Rex::Commands::SimpleCheck; |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
1
|
|
15
|
use v5.12.5; |
|
1
|
|
|
|
|
4
|
|
30
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our $VERSION = '1.14.2.2'; # TRIAL VERSION |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
1
|
|
49
|
use IO::Socket; |
|
1
|
|
|
|
|
1138
|
|
|
1
|
|
|
|
|
5
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
require Rex::Exporter; |
37
|
1
|
|
|
1
|
|
482
|
use base qw(Rex::Exporter); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
92
|
|
38
|
1
|
|
|
1
|
|
8
|
use vars qw(@EXPORT); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
211
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
@EXPORT = qw(is_port_open); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 is_port_open($ip, $port) |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Check if something is listening on port $port of $ip. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub is_port_open { |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
0
|
1
|
|
my ( $ip, $port, $type ) = @_; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
0
|
|
|
|
$type ||= "tcp"; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $socket = IO::Socket::INET->new( |
55
|
|
|
|
|
|
|
PeerAddr => $ip, |
56
|
|
|
|
|
|
|
PeerPort => $port, |
57
|
|
|
|
|
|
|
Proto => $type, |
58
|
|
|
|
|
|
|
Timeout => 2, |
59
|
|
|
|
|
|
|
Type => SOCK_STREAM |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
if ($socket) { |
63
|
0
|
|
|
|
|
|
close $socket; |
64
|
0
|
|
|
|
|
|
return 1; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return 0; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |