From: Eirik Nygaard Date: Tue, 3 Apr 2007 13:37:55 +0000 (+0200) Subject: Merge with main branch. X-Git-Url: https://git.sesse.net/?p=nms;a=commitdiff_plain;h=a78ca3c9628b209500205ad77b333bd656175f34;hp=84ddcf83d5dbeac1b6fbb18abcb132bad9f91289 Merge with main branch. --- diff --git a/clients/ciscong.pl b/clients/ciscong.pl new file mode 100644 index 0000000..80d67dd --- /dev/null +++ b/clients/ciscong.pl @@ -0,0 +1,93 @@ +#!/usr/bin/perl +# +# + +use warnings; +use strict; + +use lib '../include'; + +use Net::Telnet::Cisco; +use Net::Ping; + +use Data::Dumper; + + +BEGIN { + require "../include/config.pm"; + eval { + require "../include/config.local.pm"; + }; +} + +sub ios_getroute { + my ($t, $net) = @_; + + $t->cmd("show ip route".($net ? " $net" : '')) or return 0;; + + return 1; +} + +my $ios_server = "noc-gw.net.tg07.gathering.org"; +my $vlannumber = 16; + +#my $ios = nms::ios_connect($ios_server, $nms::config::ios_user, $nms::config::ios_pass) +# or die "Unable to connect to cisco"; + +my $ios = Net::Telnet::Cisco->new(Host => $ios_server, + Errmode => 'return', + Prompt => '/[^\s\(]+(\([^\(]\)){0,1}[#>]/'); +$ios->login($nms::config::ios_user, $nms::config::ios_pass); +$ios->enable; + +#nms::ios_enable($ios); +#$ios->cmd(); +#nms::ios_getroute($ios, "192.168.1.0"); +#$ios->cmd(""); + +#nms::ios_close($ios); + +# Disable paging +$ios->cmd("terminal length 0"); + +#my @routes = $ios->cmd("show ip route"); + +die "Already routed up 192.168.1.0/24" if (ios_getroute($ios, "192.168.1.0") == 1); + + + +$ios->cmd("conf t"); +$ios->cmd("int vlan $vlannumber"); +$ios->cmd("ip add 192.168.1.254 255.255.255.0 secondary"); +$ios->cmd("exit"); +$ios->cmd("exit"); + +my $zyxeloldip = "192.168.1.1"; + +### Do things +## ZyxelNG connect + + +my $p = Net::Ping->new(); +printf "Waiting for zyxel to come up...\n"; +while (1) { + last if $p->ping($zyxeloldip); + print "pinging...\n"; + sleep 1; +} +print "Zyxel is alive..\n"; +$p->close(); + +system("perl ./zyxelng.pl 192.168.1.1 192.168.2.1"); + +#### + +$ios->cmd("conf t"); +$ios->cmd("int vlan $vlannumber"); +$ios->cmd("no ip add 192.168.1.254 255.255.255.0 secondary"); +$ios->cmd("exit"); +$ios->cmd("exit"); + +$ios->close(); + + diff --git a/clients/zyxelng.pl b/clients/zyxelng.pl new file mode 100644 index 0000000..c3d08fc --- /dev/null +++ b/clients/zyxelng.pl @@ -0,0 +1,123 @@ +#!/usr/bin/perl -w +# +# + +use strict; +use lib '../include'; + +use Data::Dumper; + +use nms qw(switch_connect switch_exec); +#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); + +my $oldip; +my $newip; +if ($#ARGV < 1) { + die "Foo $#ARGV"; +} + +$oldip = $ARGV[0]; +$newip = $ARGV[1]; + +my $one = 0; + +my $switchip; +#$switchip = "87.76.250.226" if $one; +#$switchip = "192.168.2.150" if $one; +#$switchip = "192.168.1.1" unless $one; +$switchip = $oldip; +my $switch = switch_connect($switchip); + +my $cmds1 = <close(); + +#print "Reconnecting... "; +##$switchip = "192.168.1.1" if $one; +##$switchip = "192.168.2.150" unless $one; +#$switchip = $newip; +#autoflush STDOUT 1; +#print "Connecting to: $switchip...\n"; +#my $i = 1; +#while(1) { +# $switch = switch_connect($switchip); +# +# #print (defined($switch)? $switch : "foo") ." <---- switch\n"; +# if (defined($switch) || $switch) { +# last; +# } +# printf("Waited $i seconds...\r"); +# $i++; +# sleep 1; +#} +#print "\n"; + +#print $switch."\n"; +#$cmd = "sys sw vlan1q svlan cpu 248"; +#print "Sending '$cmd'\n"; +#print "XXX: No we did not..."; +#print Dumper($switch->cmd("ip ifconfig")); +#print Dumper($switch->cmd("ip route status")); +#switch_exec($cmd, $switch, 1); + diff --git a/include/nms.pm b/include/nms.pm index 0c0d754..b55314d 100644 --- a/include/nms.pm +++ b/include/nms.pm @@ -5,6 +5,10 @@ use DBI; use Net::Telnet; package nms; + +use base 'Exporter'; +our @EXPORT = qw(switch_connect switch_exec); + BEGIN { require "config.pm"; eval { @@ -25,10 +29,11 @@ sub db_connect { sub switch_connect($) { my ($ip) = @_; -# Dump_Log => '/tmp/dumplog-queue', my $conn = new Net::Telnet( Timeout => $nms::config::telnet_timeout, +# Dump_Log => '/tmp/dumplog-queue', Errmode => 'return', - Prompt => '/(es3024|e\d+\-\dsw)>/i'); +# Prompt => '/ES-3023>/'); + Prompt => '/(ES-3024|e\d{1,2}\-\dsw)>/i'); my $ret = $conn->open( Host => $ip); if (!$ret || $ret != 1) { return (undef); @@ -45,11 +50,17 @@ sub switch_connect($) { } # Send a command to switch and return the data recvied from the switch -sub switch_exec($$) { - my ($cmd, $conn) = @_; +sub switch_exec { + my ($cmd, $conn, $print) = @_; # Send the command and get data from switch - my @data = $conn->cmd($cmd); + my @data; + if (defined($print)) { + $conn->print($cmd); + return; + } else { + @data = $conn->cmd($cmd); + } my @lines = (); foreach my $line (@data) { # Remove escape-7 sequence