| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||||||||||||||||
| 2 | package ios_get_interfaces; | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.006001; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | our %EXPORT_TAGS = ('all' => [ qw(new get_info make_report)]); | |||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | our @EXPORT_OK = (@{$EXPORT_TAGS{'all'}}); | |||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | our @EXPORT = qw(); | |||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | our $VERSION ='1.7'; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | my ($class, $this, $router); | |||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | ▶ | sub new(){ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | $class = shift or die $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | $router = shift or die $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | $this = {name=>$router->{name}, showrun_file=>$router->{showrun_file}, csv=>$router->{csv}}; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | bless $this,$class; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | return $this; | |||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||
| 20 | ################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub get_info(){ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_info: not called CC=16 SCAR=56.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | $this = shift or die $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | my @interfaces; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | open F, $this->{showrun_file} or die "Can't find showrun file\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | my@f = <F>; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | my ($interface, $address, $description, @split1, @split2, @split3); | |||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | close F; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | foreach (@f){ | |||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | chomp $_; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | $_ =~ s/\cM//g; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | $_ =~ s/\r//g; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | if (/^interface/ .. /^!/){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if ($_ =~ /^interface/){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | @split1 = split " ", $_; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | $interface = $split1[1]; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | $description = ''; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | $address = ''; | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | if ($_ =~ /^ description/){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $description = $_; | |||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | $description =~ s/^ description //; | |||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if (($_ =~ /^ ip address/) or ($_ =~ /^ no ip address/) or ($_ =~ /^ ip unnumbered/)){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$_ =~ /^ ip address/ or $_ =~ /^ no ip address/ or $_ =~ /^ ip unnumbered/
$_ =~ /^ ip address/ or $_ =~ /^ no ip address/
MC/DC0%0/3
$_ =~ /^ ip address/ or $_ =~ /^ no ip address/ or $_ =~ /^ ip unnumbered/
$_ =~ /^ ip address/
$_ =~ /^ no ip address/
$_ =~ /^ ip unnumbered/
Truth table0%0/4
A or B or C
A= $_ =~ /^ ip address/B= $_ =~ /^ no ip address/C= $_ =~ /^ ip unnumbered/
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | @split2 = split " ", $_; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | $address = "$split2[2]-->$split2[3]" if $split2[3]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $address =~ s/\s//g; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | $address = "No IPv4 address-->No netmask" if !$split2[3]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | $this->{"Interface_".$interface."-->"} = "$address-->No description\n" if !$description; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | $this->{"Interface_".$interface."-->"} = "$address-->$description\n" if $description; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | foreach my$int (sort keys %{$this}){ | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | push @interfaces, $this->{name}."-->".$int.$this->{$int} if $int =~ /^Interface/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | return \@interfaces; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | ################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub make_report(){ | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_report: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | $this = shift or die $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | open CSV, ">$this->{csv}" or die "Can't find csv file\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | print CSV "Name;Interface;IPv4 Address;Netmask;Description\n"; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | foreach my$int (sort keys %{$this}){ | |||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my $intclean = $int; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $intclean =~ s/^Interface_//; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $intclean =~ s/-->/;/g; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | $this->{$int} =~ s/-->/;/g; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | print CSV $this->{name}.";".$intclean.$this->{$int} if $int =~ /^Interface/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | close CSV; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||||||||||||||||||||||||