lib/Rex/Commands/Network.pm

filter: Statementstmt 66.6% 24 / 36 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 70.0% 7 / 10 Podpod 100% 3 / 3 totaltotal 64.1% 34 / 53 CC 3 SCAR 13.7
CC
3
Cov
60%
default_gateway
12.0
route
2.0
netstat
2.0
CRAP 3.9
« lib/Rex/Inventory/Hal/Object/Storage.pm ↑ Summary blib/lib/Rex/TaskList/Parallel_ForkManager.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 =head1 NAME
6  
7 Rex::Commands::Network - Network Module
8  
9 =head1 DESCRIPTION
10  
11 With this module you can get information of the routing table, current network connections, open ports, ...
12  
13 =head1 SYNOPSIS
14  
15 use Rex::Commands::Network;
16  
17 my @routes = route;
18 print Dumper(\@routes);
19  
20 my $default_gw = default_gateway;
21 default_gateway "192.168.2.1";
22  
23 my @netstat = netstat;
24 my @tcp_connections = grep { $_->{"proto"} eq "tcp" } netstat;
25  
26 =head1 EXPORTED FUNCTIONS
27  
28 =cut
29  
30 package Rex::Commands::Network;
31  
32 1 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 1 our $VERSION = '1.16.1'; # VERSION
36  
37 1 require Rex::Exporter;
38 1 ▶use Rex::Commands::Gather;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶use Rex::Hardware::Network;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 1 ▶use vars qw(@EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
43 1 ▶use base qw(Rex::Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 1 @EXPORT = qw(route default_gateway netstat);
46  
47 =head2 route
48  
49 Get routing information
50  
51 =cut
52  
53 0 ▶sub route {
Subroutine route: not called CC=1 SCAR=6.9
Pod documented
54 0 return Rex::Hardware::Network::route();
55 }
56  
57 =head2 default_gateway([$default_gw])
58  
59 Get or set the default gateway.
60  
61 =cut
62  
63 0 ▶sub default_gateway {
Subroutine default_gateway: not called CC=3 SCAR=24.8
Pod documented
64 0 my $gw = shift;
65  
66 0 ▶ if ($gw) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gw) 0 0 0
67 Rex::get_current_connection()->{reporter}
68 0 ->report_resource_start( type => "default_gateway", name => $gw );
69  
70 0 my $cur_gw = Rex::Hardware::Network::default_gateway();
71  
72 0 Rex::Hardware::Network::default_gateway($gw);
73  
74 0 my $new_gw = Rex::Hardware::Network::default_gateway();
75  
76 0 ▶ if ( $cur_gw ne $new_gw ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cur_gw ne $new_gw) 0 0 0
77 Rex::get_current_connection()->{reporter}
78 0 ->report( changed => 1, message => "New default gateway $gw set." );
79 }
80  
81 Rex::get_current_connection()->{reporter}
82 0 ->report_resource_end( type => "default_gateway", name => $gw );
83 }
84  
85 0 return Rex::Hardware::Network::default_gateway();
86 }
87  
88 =head2 netstat
89  
90 Get network connection information
91  
92 =cut
93  
94 0 ▶sub netstat {
Subroutine netstat: not called CC=1 SCAR=6.9
Pod documented
95 0 return Rex::Hardware::Network::netstat();
96 }
97  
98 1 1;
« lib/Rex/Inventory/Hal/Object/Storage.pm ↑ Summary blib/lib/Rex/TaskList/Parallel_ForkManager.pm »