#!/bin/sh

PATH=$PATH:/bin:/usr/bin
export PATH

# Test page to query
PROXY_TEST=http://proxy-test.wirelessleiden.nl/

# Query the webpage
SPEEDOUT=`fetch -o /dev/null ${PROXY_TEST} 2>&1`

# What is the Exit code of fetch?
SPEEDEXIT=$?

# The speed by which the webpages was retrieved"
SPEED=`echo ${SPEEDOUT} | awk '/Bps/ { print $13 " " $14 }'`

# Dit the fetcommand exit happy, and was the format as we expected
if [ ${SPEEDEXIT} -eq 0 -a "$SPEED" ]; then

  # Let's celebrate, it was successfull
  printf "INET OK: $SPEED\n"
  exit 0
else

  # Oh no, time to get drunk, retrieval was unsuccessfull
  echo "INET CRITICAL: $SPEEDOUT\n"
  exit 2

fi

