#!/usr/bin/perl # getstat-mn7310 -- Get statistic information for 'mrtg' from MN7310. # Copyright (C) 2002 by Yoshiyuki Kondo # You may redistribute and/or modify this file under the terms of # the GNU General Public Licence as published by the Free Software # Foundation. # NO WARRANTY # IMPORTANT: This file should be chmod 700. # # $Header: /home/proj/adm/derby/mrtg/RCS/getstat-mn7310,v 1.1 2002/09/11 09:17:40 cond Exp $ # ルーターの名前 $routername = 'router-o'; # ルーターのパスワード $passwd = '*******'; # ---------------------------------------------------------------------- # これ以降の部分はいじらないこと。 use IO::Socket; use MIME::Base64; # ルータにコネクトする $remote = IO::Socket::INET->new(PeerAddr => $routername, PeerPort => 'http(80)', Proto => 'tcp'); unless ($remote) { die "Cannot connect to http port on $routername\n"; } $remote->autoflush(1); # 統計情報のページを取り出す print $remote "GET /cgi-bin/main.cgi?cc_webname=STATISTICS HTTP/1.0\n"; # 認証パスワードを送る print $remote "Authorization: Basic ", encode_base64("user:$passwd"), "\n"; # ルータからの応答を読み込む @lines = <$remote>; close $remote; # 統計情報から必要なデータを取り出す foreach (@lines) { if (/ifInOctets<.*?>(\d+)/) { # 受信バイト数 $recv = $1; } if (/ifOutOctets<.*?>(\d+)/) { # 送信バイト数 $trans = $1; } } # 結果を出力する print $recv, "\n"; # 受信バイト数 print $trans, "\n"; # 送信バイト数 print "UNKNOWN\n"; # Uptime print $routername, "\n"; # ルータ名