| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #!/usr/bin/perl | 
| 2 |  |  |  |  |  |  | package ios_get_interfaces; | 
| 3 | 1 |  |  | 1 |  | 6461 | use 5.006001; | 
|  | 1 |  |  |  |  | 7 |  | 
| 4 | 1 |  |  | 1 |  | 9 | use strict; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 32 |  | 
| 5 | 1 |  |  | 1 |  | 9 | use warnings; | 
|  | 1 |  |  |  |  | 8 |  | 
|  | 1 |  |  |  |  | 1533 |  | 
| 6 |  |  |  |  |  |  | require Exporter; | 
| 7 |  |  |  |  |  |  | our @ISA = qw(Exporter); | 
| 8 |  |  |  |  |  |  | our %EXPORT_TAGS = ('all' => [ qw(new get_info make_report)]); | 
| 9 |  |  |  |  |  |  | our @EXPORT_OK = (@{$EXPORT_TAGS{'all'}}); | 
| 10 |  |  |  |  |  |  | our @EXPORT = qw(); | 
| 11 |  |  |  |  |  |  | our $VERSION ='1.7'; | 
| 12 |  |  |  |  |  |  | my ($class, $this, $router); | 
| 13 |  |  |  |  |  |  | sub new(){ | 
| 14 | 0 | 0 |  | 0 | 0 |  | $class = shift or die $!; | 
| 15 | 0 | 0 |  |  |  |  | $router = shift or die $!; | 
| 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 |  |  |  |  |  |  | sub get_info(){ | 
| 22 | 0 | 0 |  | 0 | 0 |  | $this = shift or die $!; | 
| 23 | 0 |  |  |  |  |  | my @interfaces; | 
| 24 | 0 | 0 |  |  |  |  | open F, $this->{showrun_file} or die "Can't find showrun file\n"; | 
| 25 | 0 |  |  |  |  |  | my@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 | 0 |  |  |  |  | if (/^interface/ .. /^!/){ | 
| 33 | 0 | 0 |  |  |  |  | if ($_ =~ /^interface/){ | 
| 34 | 0 |  |  |  |  |  | @split1 = split " ", $_; | 
| 35 | 0 |  |  |  |  |  | $interface = $split1[1]; | 
| 36 | 0 |  |  |  |  |  | $description = ''; | 
| 37 | 0 |  |  |  |  |  | $address = ''; | 
| 38 |  |  |  |  |  |  | } | 
| 39 | 0 | 0 |  |  |  |  | if ($_ =~ /^ description/){ | 
| 40 | 0 |  |  |  |  |  | $description = $_; | 
| 41 | 0 |  |  |  |  |  | $description =~ s/^ description //; | 
| 42 |  |  |  |  |  |  | } | 
| 43 | 0 | 0 | 0 |  |  |  | if (($_ =~ /^ ip address/) or ($_ =~ /^ no ip address/) or ($_ =~ /^ ip unnumbered/)){ | 
|  |  |  | 0 |  |  |  |  | 
| 44 | 0 |  |  |  |  |  | @split2 = split " ", $_; | 
| 45 | 0 | 0 |  |  |  |  | $address = "$split2[2]-->$split2[3]" if $split2[3]; | 
| 46 | 0 |  |  |  |  |  | $address =~ s/\s//g; | 
| 47 | 0 | 0 |  |  |  |  | $address = "No IPv4 address-->No netmask" if !$split2[3]; | 
| 48 | 0 | 0 |  |  |  |  | $this->{"Interface_".$interface."-->"} = "$address-->No description\n" if !$description; | 
| 49 | 0 | 0 |  |  |  |  | $this->{"Interface_".$interface."-->"} = "$address-->$description\n" if $description; | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  | } | 
| 53 | 0 |  |  |  |  |  | foreach my$int (sort keys %{$this}){ | 
|  | 0 |  |  |  |  |  |  | 
| 54 | 0 | 0 |  |  |  |  | push @interfaces, $this->{name}."-->".$int.$this->{$int} if $int =~ /^Interface/; | 
| 55 |  |  |  |  |  |  | } | 
| 56 | 0 |  |  |  |  |  | return \@interfaces; | 
| 57 |  |  |  |  |  |  | } | 
| 58 |  |  |  |  |  |  | ################################################### | 
| 59 |  |  |  |  |  |  | sub make_report(){ | 
| 60 | 0 | 0 |  | 0 | 0 |  | $this = shift or die $!; | 
| 61 | 0 | 0 |  |  |  |  | open CSV, ">$this->{csv}" or die "Can't find csv file\n"; | 
| 62 | 0 |  |  |  |  |  | print CSV "Name;Interface;IPv4 Address;Netmask;Description\n"; | 
| 63 | 0 |  |  |  |  |  | foreach my$int (sort keys %{$this}){ | 
|  | 0 |  |  |  |  |  |  | 
| 64 | 0 |  |  |  |  |  | my $intclean = $int; | 
| 65 | 0 |  |  |  |  |  | $intclean =~ s/^Interface_//; | 
| 66 | 0 |  |  |  |  |  | $intclean =~ s/-->/;/g; | 
| 67 | 0 |  |  |  |  |  | $this->{$int} =~ s/-->/;/g; | 
| 68 | 0 | 0 |  |  |  |  | print CSV $this->{name}.";".$intclean.$this->{$int} if $int =~ /^Interface/; | 
| 69 |  |  |  |  |  |  | } | 
| 70 | 0 |  |  |  |  |  | close CSV; | 
| 71 |  |  |  |  |  |  | } | 
| 72 |  |  |  |  |  |  | return 1; | 
| 73 |  |  |  |  |  |  | __END__ |