#!/usr/bin/perl #------------------------------------------------------------------------------ # ===== # mn128 # ===== # # (Function) # Connect or disconnect to a remote host via MN128/SOHO. # (Usage) # $ mn128 {-c [0-15] | -d [ all | b1 | b2 ] | -s [? | info_type]} # - --- - # where underlined are the default values. # (Update Record) # 1999/08/12 K.Fujii A very primitive perl version derived from # the ruby version by setsura@remus.dti.ne.jp. # 1999/08/14 K.Fujii Modified to accept a subparameter such as # "list" in the following example: # $ mn128 -s remote:list # This will execute # show remote list # in the MN128/SOHO. # #------------------------------------------------------------------------------ #-- # Site dependent parameters. # host : local ip for MN128/SOHO # user : user name in MN128/SOHO # passwd : passwd for the user #-- $host = "192.168.0.1"; # You probably don't need to modify this $user = "admin"; # and this. $passwd = "yourpasswd"; # But you have to modify this for sure. #-- # Declare packages to use. #-- use Getopt::Std; use Net::Telnet; #-- # Parse arguments. # - [] # %optb : boolean set if the option given # %opts : string carrying the value of the option #-- @temp = @ARGV; getopts('scd',\%optb); @ARGV = @temp; getopts('s:c:d:',\%opts); #-- # Usage. #-- sub usage { print "Usage:\n"; print "\$ mn128 {-c [0-15] | -d [ all | b1 | b2 ] | -s [info_type]}\n"; exit 0; } #-- # Decide the command to execute after logging in MN128/SOHO. #-- if ($optb{'s'}) { $opt = $opts{'s'}; $opt =~ s/:/ /; $cmd = "show " . $opt; } elsif ($optb{'c'}) { $opt = $opts{'c'}; if ($opt == "") { $opt = "0"; } elsif ($opt < 0 || $opt > 15) { usage; } $cmd = "connect " . $opt; } elsif ($optb{'d'}) { $opt = $opts{'d'}; if ($opt == "" || $opt == "all") { $opt = "all"; } elsif ($opt != "b1" && $opt != "b2" && $opt != "pptp1" && $opt != "pptp2") { usage; } $cmd = "disconnect " . $opt; } else { usage; } # print "cmd = $cmd\n"; #-- # Telnet to MN128/SOHO #-- $t = new Net::Telnet (); $t->open($host); $t->login($user, $passwd); #-- # Execute the command and log out. #-- @lines = $t->cmd($cmd); print @lines; print "\n"; $t->close; #-- # That's it, folks! #-- exit 0;