]> git.sesse.net Git - nms/blob - clients/zyxelng.pl
* Better error message.
[nms] / clients / zyxelng.pl
1 #!/usr/bin/perl -w
2 #
3 #
4
5 use strict;
6 use lib '../include';
7
8 use Data::Dumper;
9
10 use nms qw(switch_connect switch_exec);
11 #use ios;
12
13 #my $t = nms::ios_connect('62.148.36.12', 'c', 'c', 'c');
14
15 #print STDERR "No such network 192.168.1.0\n" if nms::ios_getroute($t, "192.168.1.0") == 0;
16
17 #nms::ios_close($t);
18
19 if ($#ARGV < 1) {
20         die "Not enough arguments to zyxelng.pl $#ARGV";
21 }
22
23 my $oldip = $ARGV[0];
24 my $newip = $ARGV[1];
25 #$switchname = $ARGV[2];
26
27 my $one = 0;
28
29 my $switchip;
30 #$switchip = "87.76.250.226" if $one;
31 #$switchip = "192.168.2.150" if $one;
32 #$switchip = "192.168.1.1" unless $one;
33 $switchip = $oldip;
34 my $switch = switch_connect($switchip)
35         or die "Could not connect to $switchip";
36
37 my $cmds1 = <<EOF
38 sys hostname es-3024
39 ip igmpsnoop enable
40 EOF
41 ;
42
43 foreach (split(/\n+/, $cmds1)) {
44         print "Sending: '$_'\n";
45         switch_exec($_, $switch);
46 }
47
48 my $cmd;
49 #$cmd = "ip ifconfig swif0 192.168.1.1/24" if $one;
50 #$cmd = "ip ifconfig swif0 192.168.2.150/24" unless $one;
51 $cmd = "ip ifconfig swif0 $newip/30";
52
53 print "Sending '$cmd'\n";
54 my $pid = fork();
55 if ($pid == 0) {
56         print "Sending ifconfig.. $cmd\n";
57         switch_exec($cmd, $switch);
58         exit 0;
59 } else {
60         #switch_exec($cmd, $switch, 1);
61         print "Sleeping...\n";
62         sleep 1;
63 }
64 $switch->close();
65
66 #print "Reconnecting... ";
67 ##$switchip = "192.168.1.1" if $one;
68 ##$switchip = "192.168.2.150" unless $one;
69 #$switchip = $newip;
70 #autoflush STDOUT 1;
71 #print "Connecting to: $switchip...\n";
72 #my $i = 1;
73 #while(1) {
74 #       $switch = switch_connect($switchip);
75 #       
76 #       #print (defined($switch)? $switch : "foo") ." <---- switch\n";
77 #       if (defined($switch) || $switch) {
78 #               last;
79 #       }
80 #       printf("Waited $i seconds...\r");
81 #       $i++;
82 #       sleep 1;
83 #}
84 #print "\n";
85
86 #print $switch."\n";
87 #$cmd = "sys sw vlan1q svlan cpu 248";
88 #print "Sending '$cmd'\n";
89 #print "XXX: No we did not...";
90 #print Dumper($switch->cmd("ip ifconfig"));
91 #print Dumper($switch->cmd("ip route status"));
92 #switch_exec($cmd, $switch, 1);
93