line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# network::traceroute Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::Network::Traceroute; |
7
|
1
|
|
|
1
|
|
691
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
8
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Metabrik::Shell::Command Metabrik::System::Package); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
593
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Default attribute values put here will BE inherited by subclasses |
13
|
|
|
|
|
|
|
sub brik_properties { |
14
|
|
|
|
|
|
|
return { |
15
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
16
|
|
|
|
|
|
|
tags => [ qw(unstable) ], |
17
|
|
|
|
|
|
|
author => 'GomoR ', |
18
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
19
|
|
|
|
|
|
|
attributes => { |
20
|
|
|
|
|
|
|
first_hop => [ qw(hop_number) ], |
21
|
|
|
|
|
|
|
last_hop => [ qw(hop_number) ], |
22
|
|
|
|
|
|
|
rtimeout => [ qw(timeout_second) ], |
23
|
|
|
|
|
|
|
try => [ qw(try_count) ], |
24
|
|
|
|
|
|
|
}, |
25
|
|
|
|
|
|
|
attributes_default => { |
26
|
|
|
|
|
|
|
first_hop => 5, |
27
|
|
|
|
|
|
|
last_hop => 50, |
28
|
|
|
|
|
|
|
rtimeout => 1, |
29
|
|
|
|
|
|
|
try => 2, |
30
|
|
|
|
|
|
|
}, |
31
|
|
|
|
|
|
|
commands => { |
32
|
|
|
|
|
|
|
install => [ ], # Inherited |
33
|
|
|
|
|
|
|
tcp => [ qw(host port) ], |
34
|
|
|
|
|
|
|
}, |
35
|
|
|
|
|
|
|
require_binaries => { |
36
|
|
|
|
|
|
|
'tcptraceroute', => [ ], |
37
|
|
|
|
|
|
|
}, |
38
|
|
|
|
|
|
|
need_packages => { |
39
|
|
|
|
|
|
|
ubuntu => [ qw(tcptraceroute) ], |
40
|
|
|
|
|
|
|
debian => [ qw(tcptraceroute) ], |
41
|
|
|
|
|
|
|
kali => [ qw(tcptraceroute) ], |
42
|
|
|
|
|
|
|
}, |
43
|
|
|
|
|
|
|
}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub tcp { |
47
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
48
|
0
|
|
|
|
|
|
my ($host, $port) = @_; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $rtimeout = $self->rtimeout; |
51
|
0
|
|
|
|
|
|
my $try = $self->try; |
52
|
0
|
|
|
|
|
|
my $first = $self->first_hop; |
53
|
0
|
|
|
|
|
|
my $last = $self->last_hop; |
54
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('tcp', $host) or return; |
55
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('tcp', $port) or return; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my $cmd = "tcptraceroute -n -q $try -f $first -m $last -w $rtimeout $host $port"; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
$self->log->verbose("tcp: running..."); |
60
|
0
|
|
|
|
|
|
my $lines = $self->capture($cmd); |
61
|
0
|
|
|
|
|
|
$self->log->verbose("tcp: running...Done"); |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $trace = { |
64
|
|
|
|
|
|
|
raw => $lines, |
65
|
|
|
|
|
|
|
}; |
66
|
0
|
|
|
|
|
|
for my $this (@$lines) { |
67
|
0
|
|
|
|
|
|
(my $l = $this) =~ s/^\s*//; |
68
|
0
|
0
|
|
|
|
|
if ($l =~ /^\d+/) { |
69
|
0
|
|
|
|
|
|
my @toks = split(/\s+/, $l); |
70
|
0
|
|
|
|
|
|
my $hop = $toks[0]; |
71
|
0
|
|
|
|
|
|
my $ip; |
72
|
0
|
|
|
|
|
|
for (1..$try) { |
73
|
0
|
|
|
|
|
|
my $i = $toks[$_]; |
74
|
0
|
0
|
|
|
|
|
if ($i =~ /^\d+\.\d+\.\d+\.\d+$/) { |
75
|
0
|
|
|
|
|
|
$ip = $i; |
76
|
0
|
|
|
|
|
|
last; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
0
|
|
0
|
|
|
|
$trace->{$hop} = $ip || '0.0.0.0'; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return $trace; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |