Network/Traceroute.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Network/Stream.pm ↑ Summary Network/Whois.pm »
1 #
2 # $Id$
3 #
4 # network::traceroute Brik
5 #
6 package Metabrik::Network::Traceroute;
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use base qw(Metabrik::Shell::Command Metabrik::System::Package);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # Default attribute values put here will BE inherited by subclasses
13 sub brik_properties {
14 return {
15 revision => '$Revision$',
16 tags => [ qw(unstable) ],
17 author => 'GomoR <GomoR[at]metabrik.org>',
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 my $self = shift;
48 my ($host, $port) = @_;
49  
50 my $rtimeout = $self->rtimeout;
51 my $try = $self->try;
52 my $first = $self->first_hop;
53 my $last = $self->last_hop;
54 $self->brik_help_run_undef_arg('tcp', $host) or return;
55 $self->brik_help_run_undef_arg('tcp', $port) or return;
56  
57 my $cmd = "tcptraceroute -n -q $try -f $first -m $last -w $rtimeout $host $port";
58  
59 $self->log->verbose("tcp: running...");
60 my $lines = $self->capture($cmd);
61 $self->log->verbose("tcp: running...Done");
62  
63 my $trace = {
64 raw => $lines,
65 };
66 for my $this (@$lines) {
67 (my $l = $this) =~ s/^\s*//;
68 if ($l =~ /^\d+/) {
69 my @toks = split(/\s+/, $l);
70 my $hop = $toks[0];
71 my $ip;
72 for (1..$try) {
73 my $i = $toks[$_];
74 if ($i =~ /^\d+\.\d+\.\d+\.\d+$/) {
75 $ip = $i;
76 last;
77 }
78 }
79 $trace->{$hop} = $ip || '0.0.0.0';
80 }
81 }
82  
83 return $trace;
84 }
85  
86 1;
87  
88 __END__
« Network/Stream.pm ↑ Summary Network/Whois.pm »