1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Is there a way to log internet connectivity?

Discussion in 'Tomato Firmware' started by cspyr0, Jul 10, 2011.

  1. cspyr0

    cspyr0 Networkin' Nut Member

    Are there any extensions (or perhaps built-in functions that I've missed) that log internet connectivity? My internet has been sporadic recently, and I'd like to be able to track it. Something that just pings a server constantly and can output a report of some sort would do nicely.
     
  2. Toxic

    Toxic Administrator Staff Member

    is DNS playing up perhaps?
     
  3. cspyr0

    cspyr0 Networkin' Nut Member

    I'm not really interested in what's causing the connectivity issues, for the purposes of this post. Regardless of present and future problems, I'm searching for a tool to log when my connection is up/down.
     
  4. ntest7

    ntest7 Network Guru Member

    I have a script that will log when the internet is down.

    I have some networks with two gateways -- a fast cable connection and a slower (but more reliable) T1 connection. My Tomato gateway monitors the internet and switches to the slower T1 when the cable goes down. You can comment out the "route del ..." lines to disable the gateway switching. Change the PINGHOST as desired; I'm using an OpenDNS server as the target since it's just about always up. Another good candidate for PINGHOST may be the first 'hop' of a traceroute command on your router.

    Under normal conditions, nothing is logged.

    When the cable fails, system logs something like:
    Jul 12 11:30:03 leb-wlan1 user.notice watch_route: FAILCOUNT=1
    Jul 12 11:30:58 leb-wlan1 user.notice watch_route: FAILCOUNT=2
    Jul 12 11:30:58 leb-wlan1 user.notice watch_route: routing to lan 192.168.1.1
    Jul 12 11:31:53 leb-wlan1 user.notice watch_route: FAILCOUNT=3
    Jul 12 11:32:48 leb-wlan1 user.notice watch_route: FAILCOUNT=4

    and when the cable is back up:
    Jul 12 11:42:42 leb-wlan1 user.notice watch_route: routing to cable 192.1.2.1


    Code:
    echo '#!/bin/sh
    CABLEGW=`nvram get wan_gateway`
    LANGW=`nvram get lan_ipaddr | cut -d. -f1,2,3`.1
    PINGHOST=208.67.222.222
    MYGW=c
    PATH='/bin:/usr/bin:/sbin:/usr/sbin'
    route add $PINGHOST gw $CABLEGW
    let FAILCOUNT=0
    route_cable() {
    logger -s -t watch_route routing to cable $CABLEGW
    route del default && route add default gw $CABLEGW && MYGW=c
    }
    route_lan() {
    logger -s -t watch_route routing to lan $LANGW
    route del default && route add default gw $LANGW && MYGW=l
    }
    logger -s -t watch_route starting: langw $LANGW, cablegw $CABLEGW
    while sleep 40 ; do
    if ping -c 3 -w 15 $PINGHOST >/dev/null
    then let FAILCOUNT=0
    else let FAILCOUNT=$FAILCOUNT+1
    logger -s -t watch_route FAILCOUNT=$FAILCOUNT
    fi
    if [ $FAILCOUNT -ge 2 ]
    then if [ $MYGW = "c" ] ; then route_lan ; fi
    else if [ $MYGW = "l" ] ; then route_cable ; fi
    fi
    done' > /tmp/watch_route
    chmod 755 /tmp/watch_route
    /usr/bin/nohup /tmp/watch_route >/dev/null 2>&1 &
    
     
  5. cspyr0

    cspyr0 Networkin' Nut Member

    Brilliant, thank you!
     

Share This Page