Persisting the Netgear Traffic Meter using expect

by cmur2 on 2013-12-24 in expect , netgear , router

If you are in the situation of having a Netgear product that runs the TeamF1 firmware like a FVS318/FVS318G or FVS338/FVS338G (and cannot switch to something better) you probably want to use the “Traffic Meter” that does traffic accounting for your broadband connection…

But there is a major drawback: the Traffic Meter loses your statistics on each power cycle :(

While this script can not fully overcome these limitations, it makes dealing with them easier. It queries the traffic statistics using the telnet CLI in an easily machine-parsable format (grep and cut are your friends here) using an expect script which is suited for automating highly interactive commands (like telnet).

First the script (derived from this):

#!/usr/bin/expect
set timeout 20
set name [lindex $argv 0]
set user [lindex $argv 1]
set password [lindex $argv 2]
spawn telnet $name
expect "login: "
send "$user\n"
expect "Password: "
send "$password\n"
expect "$ "
send "monitor/trafficMtr/summary wanId 1\n" # use first WAN interface
expect "Percentage of this Month's Limit"
expect "$ "
send "exit\n"
expect eof

The first part does parsing the scripts parameters and specifying the executable to launch, the second part then does the communication with your router using the send (sends some characters) and expect (waits until the given characters are received) statements. For the script to function you may need to install the expect package on your system.

Use it like this:

./trafficMtr.sh <host> <username> <password>

Now you can use the output anyway you like, grepping it, storing it, etc. in order to persist the traffic statistics using a cron job so that even in case of a power cycle that information is not lost.

The post »Persisting the Netgear Traffic Meter using expect«
is licensed under Creative Commons BY-NC-SA 3.0.

cmur2

https://www.mycrobase.de/

GitHub