From: Eirik A. Nygaard Date: Sun, 1 Apr 2007 11:27:59 +0000 (+0200) Subject: Add cisco auth and basic ios handling for zyxelng. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=31834d967b81557a519d32c881d0fc42fe11dfee;p=nms Add cisco auth and basic ios handling for zyxelng. --- diff --git a/clients/zyxelng.pl b/clients/zyxelng.pl new file mode 100644 index 0000000..e46f0fb --- /dev/null +++ b/clients/zyxelng.pl @@ -0,0 +1,17 @@ +#!/usr/bin/perl -w +# +# + +use strict; +use lib '../include'; + +use nms; +use ios; + + +my $t = nms::ios_connect('62.148.36.12', 'c', 'c', 'c'); + +print STDERR "No such network 192.168.1.0\n" if nms::ios_getroute($t, "192.168.1.0") == 0; + +nms::ios_close($t); + diff --git a/include/ios.pm b/include/ios.pm new file mode 100644 index 0000000..750a96b --- /dev/null +++ b/include/ios.pm @@ -0,0 +1,79 @@ +#!/usr/bin/perl -w + +use strict; + +use Net::Telnet; + +package nms; + +my $iosprompt = '/[^\s]+[#>]/'; + +sub ios_waitprompt($) { + my ($t) = @_; + + #while ($t->getline) { + # print "Line: $_\n" if $_; + #} + + my ($prematch, $match) = $t->waitfor($iosprompt); + #print "PRE: $prematch\nM: $match\n"; +} + +sub ios_enable($$) { + my ($t, $enablepass) = @_; + + print STDERR "Enabling...\n"; + my @lines = $t->print("enable"); + $t->waitfor('/Password: /'); + $t->print($enablepass); + ios_waitprompt($t); +} + +sub ios_login($$$) { + my ($t, $user, $pass) = @_; + + print STDERR "Waiting username\n"; + my ($prematch, $match) = $t->waitfor('/Username:\s{0,}/'); + print STDERR "Sending username\n"; + $t->print($user); + print STDERR "Waiting password\n"; + ($prematch, $match) = $t->waitfor('/Password: /'); + print STDERR "Sending password\n"; + $t->print($pass); + + ios_waitprompt($t); +} + +sub ios_getroute { + my ($t, $net) = @_; + + my @output = $t->cmd("show ip route".($net ? " $net" : '')); + + foreach (@output) { + return 0 if $_ =~ /^% Network not in table/; + } + + return 1; +} + +sub ios_connect { + my ($host, $user, $pass, $enablepass) = @_; + + my $t = new Net::Telnet(Timeout => 15, + Prompt => $iosprompt); + $t->dump_log("/tmp/ios.log"); + $t->open($host); + ios_login($t, $user, $pass); + ios_enable($t, $enablepass) if $enablepass; + $t->cmd("terminal length 0"); # Don't use the pager + + return $t; +} + +sub ios_close($) { + my ($t) = @_; + + $t->print('quit'); + $t->close; +} +