#!/usr/bin/perl ### RTA50i 動作状況取得スクリプト@急ごしらえ版 # http://www.rtpro.yamaha.co.jp/RT/FAQ/Config/telnet-script.htmlより基本はパクり。 # #by Makosuke. / 2001.9.20 # #使用・改変はご自由に:-)。なお、スクリプトはEUCで保存する事。 #要 Net::Telnet, Jcode.pm。 # #使い方 # 他のスクリプトから # require './rta50icon.pl'; # ($status, $ipaddr) = &rta50icon'getstatus; # とする。 # # 戻り値: $status ... Trueなら回線接続中, Falseならばそれ以外(切断か処理中) # $ipaddr ... 現在のIPアドレス。$statusがTrueの場合以外は不定値(じゃないかなぁ) # # 下の「各種設定」部分を適当に変更してお使い下さい。 package rta50icon; ### 各種設定 $routerip = '192.168.0.1'; # RTA50iのIPアドレス $routerpp = '1'; # チェックするpp (1か2) $routerpwd = '******'; # ルータのログインパスワード sub getstatus { use Net::Telnet; use Jcode; $t = new Net::Telnet (-host => "$routerip"); #Login $t->waitfor ('/Password:.*$/'); $t->print ("$routerpwd"); #Get Info. $t->waitfor ('/>.*$/'); $t->print ("show status pp $routerpp"); ($lines) = $t->waitfor ('/>.*$/'); $lines = jcode($lines)->euc; ($ipaddress) = $lines =~ /PP IP Address Local: (\d+.\d+.\d+.\d+),/; $linestatus = ($lines =~ /回線は接続されています/); #Router logoff $t->print ("quit"); $t->close; return ($linestatus, $ipaddress); }