]> git.sesse.net Git - nms/commitdiff
Add cisco auth and basic ios handling for zyxelng.
authorEirik A. Nygaard <eirikald@pvv.ntnu.no>
Sun, 1 Apr 2007 11:27:59 +0000 (13:27 +0200)
committerEirik A. Nygaard <eirikald@pvv.ntnu.no>
Sun, 1 Apr 2007 11:27:59 +0000 (13:27 +0200)
clients/zyxelng.pl [new file with mode: 0644]
include/ios.pm [new file with mode: 0644]

diff --git a/clients/zyxelng.pl b/clients/zyxelng.pl
new file mode 100644 (file)
index 0000000..e46f0fb
--- /dev/null
@@ -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 (file)
index 0000000..750a96b
--- /dev/null
@@ -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;
+}
+