10 use Net::Telnet::Cisco;
15 my $patchlist = "/root/patchlist.txt";
16 my $switches = "/root/switches.txt";
17 #my $patchlist = "/home/eirikn/patchlist.txt.eirik";
18 #my $switches = "/home/eirikn/switches.txt.eirik";
19 #my $patchlist = "/root/patchlist.txt.d05";
20 #my $switches = "/root/switches.txt.d05";
22 open LOG, ">>/tmp/zyxel.could.not.connect2" or die "Could not open log";
26 require "../include/config.pm";
28 require "../include/config.local.pm";
35 $t->cmd("show ip route".($net ? " $net" : '')) or return 0;;
40 #my $ios_server = "noc-gw.net.tg07.gathering.org";
43 #my $ios = nms::ios_connect($ios_server, $nms::config::ios_user, $nms::config::ios_pass)
44 # or die "Unable to connect to cisco";
48 my ($dip, $newip, $net, $switchname) = @_;
50 my $ios = Net::Telnet::Cisco->new(Host => $dip,
52 Prompt => '/(\S+[#>])|(es-3024>)/');
53 # Prompt => '/[^\s\(]+(\([^\(]\)){0,1}[#>]/');
55 print "Could not connect to $dip";
58 $ios->login($nms::config::ios_user, $nms::config::ios_pass);
61 #nms::ios_enable($ios);
63 #nms::ios_getroute($ios, "192.168.1.0");
66 #nms::ios_close($ios);
69 $ios->cmd("terminal length 0");
71 #my @routes = $ios->cmd("show ip route");
74 $ios->print("telnet $newip");
75 $ios->waitfor("/Password:/");
77 $ios->cmd($nms::config::zyxel_password);
79 my ($first, $second, $third, $fourth) = split(/\./, $net);
80 my $gw = "$first.$second.$third.".(int($fourth)+1);
81 $ios->cmd("ip route drop 192.168.1.0/24");
82 $ios->cmd("ip route add default $gw");
85 #system("perl ./zyxelng.pl 192.168.1.1 $newip $switchname");
97 open(SWITCHES, $switches) or die "Unable to open switches";
99 my ($ip, $net, $name) = split;
101 if ($name =~ /e\d+-\d/) {
102 die "We only support /26 nets for now you wanted $net" if ($net ne "26");
103 $switchips{$name} = $ip;
109 my ($switch, $distro, $port) = @_;
111 $switch =~ /e(\d+)-(\d)/;
112 my ($row, $place) = ($1, $2);
113 my $ipnet = $switchips{$switch};
114 my $vlan = $row . $place;
115 my ($first, $second, $third, $fourth) = split(/\./, $ipnet);
116 my $ip = "$first.$second.$third.".(int($fourth)+2);
117 my $dip = $distro.".net.tg07.gathering.org";
119 return ($row, $place, $ipnet, $vlan, $ip, $dip);
124 open(PATCHLIST, $patchlist) or die "Unable to open patchlist";
125 while (<PATCHLIST>) {
126 my ($switch, $distro, $port) = split;
128 next if (defined($ARGV[0]) and $ARGV[0] ne $switch);
130 print "First run...\n";
131 my ($row, $place, $ipnet, $vlan, $ip, $dip) = switch_info($switch, $distro, $port);
132 print "Switch: $switch, Distro: $distro, vlan: $vlan\n";
133 print "Ip net: $ipnet\n";
136 do_distro($dip, $ip, $ipnet, $switch);
137 # my ($dip, $newip, $vlan) = @_;