Skip to content

Instantly share code, notes, and snippets.

@jiphex
Created July 13, 2009 22:46
Show Gist options
  • Save jiphex/146504 to your computer and use it in GitHub Desktop.
Save jiphex/146504 to your computer and use it in GitHub Desktop.
Script for Tomato Firmware based routers to detect Virgin Media (UK) traffic shaping, then trigger events such as LED switching and backend calling (e.g To Twitter)
#! /bin/sh
PINGHOST="212.58.226.77" # BBC news
THROTTLEFILE="/tmp/throttlestate"
PINGTIME=`ping -c 5 -q $PINGHOST | grep ^round | cut -d "/" -f 4 | cut -d "." -f 1`
WASTHROTTLED=`cat $THROTTLEFILE`
PINGISGT=`expr $PINGTIME \> 100`
if [ $PINGISGT -eq 1 ]; then
echo "I think I'm throttled (with a ping of $PINGTIME ms)"
THROTTLESTATE="yes"
else
echo "I'm probably not throttled (with a ping of $PINGTIME ms)"
THROTTLESTATE="no"
fi
echo $THROTTLESTATE > $THROTTLEFILE
if [ $THROTTLESTATE == $WASTHROTTLED ]; then
echo "No state change detected, no action required."
if [ $THROTTLESTATE == "yes" ]; then
echo "We are throttled however..."
led amber on
else
led amber off
fi
else
echo "State change detected $WASTHROTTLED => $THROTTLESTATE"
wget -O /dev/null http://some.host.net/backend/$THROTTLESTATE.php?throttled=$PINGTIME
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment