10 use Net::Telnet::Cisco;
15 #my $patchlist = "/home/eirikn/patchlist.txt";
16 #my $switches = "/home/eirikn/switches.txt";
17 my $patchlist = "/home/eirikn/patchlist.txt.eirik";
18 my $switches = "/home/eirikn/switches.txt.eirik";
21 require "../include/config.pm";
23 require "../include/config.local.pm";
30 $t->cmd("show ip route".($net ? " $net" : '')) or return 0;;
35 #my $ios_server = "noc-gw.net.tg07.gathering.org";
38 #my $ios = nms::ios_connect($ios_server, $nms::config::ios_user, $nms::config::ios_pass)
39 # or die "Unable to connect to cisco";
44 my ($dip, $newip, $vlan) = @_;
46 my $ios = Net::Telnet::Cisco->new(Host => $dip,
48 Prompt => '/[^\s\(]+(\([^\(]\)){0,1}[#>]/');
49 $ios->login($nms::config::ios_user, $nms::config::ios_pass);
52 #nms::ios_enable($ios);
54 #nms::ios_getroute($ios, "192.168.1.0");
57 #nms::ios_close($ios);
60 $ios->cmd("terminal length 0");
62 #my @routes = $ios->cmd("show ip route");
64 if (ios_getroute($ios, "192.168.1.0") == 1) {
65 print "Already routed up 192.168.1.0/24\n" ;
70 $ios->cmd("int vlan $vlan");
71 $ios->cmd("ip add 192.168.1.254 255.255.255.0 secondary");
75 my $zyxeloldip = "192.168.1.1";
80 my $p = Net::Ping->new();
81 printf "Waiting for zyxel to come up...\n";
83 last if $p->ping($zyxeloldip);
87 print "Zyxel is alive..\n";
90 system("perl ./zyxelng.pl 192.168.1.1 $newip");
95 $ios->cmd("int vlan $vlan");
96 $ios->cmd("no ip add 192.168.1.254 255.255.255.0 secondary");
106 ## Collect switch ips
110 open(SWITCHES, $switches) or die "Unable to open switches";
112 my ($ip, $net, $name) = split;
115 if ($name =~ /e\d+-\d/) {
116 die "We only support /26 nets for now you wanted $net" if ($net ne "26");
117 $switchips{$name} = $ip;
123 open(PATCHLIST, $patchlist) or die "Unable to open patchlist";
124 while (<PATCHLIST>) {
125 my ($switch, $distro, $port) = split;
127 $switch =~ /e(\d+)-(\d)/;
128 my ($row, $place) = ($1, $2);
129 my $ipnet = $switchips{$switch};
130 my $vlan = $row . $place;
131 print "Switch: $switch, Distro: $distro, vlan: $vlan\n";
132 print "Ip net: $ipnet\n";
133 my ($first, $second, $third, $fourth) = split(/\./, $ipnet);
134 my $ip = "$first.$second.$third.".(int($fourth)+2);
136 my $dip = $distro.".net.tg07.gathering.org";
138 do_distro($dip, $ip, $vlan);
139 # my ($dip, $newip, $vlan) = @_;