ShaneMcC.co.uk :: ADSL :: Enta Centra Checker

 
Notes
This script works by starting a traceroute to noc.enta.net and checking the first few hops (only 2 hops are used if traceroute-nanog is installed, else all hops are used) for the first .dsl.enta.net hop, this is the LNS.
Once the LNS is found, the central number is discovered by checking the list of known centrals at the bottom of the script.

In extended information mode, the contents of http://noc.enta.net are parsed to get the colour and expected speed for the current central.

This script should work on Linux, OS X and BSD (or any other OS with bash, traceroute and either wget, curl or fetch)
Code
You can download this script here
#!/bin/sh
#
# Quick Script to check Entanet central number, can also grab expected speed
# from noc.enta.net if -a is passed as the first param.
# Central <-> LNS mapping correct as of 3rd July 2008 04:00
#
# Example:
# [04:34:32] [shane@Xion:~]$ enta-central-checker
# Central Number: 5 (LNS: m.dsl.enta.net)
# [04:34:37] [shane@Xion:~]$
#
# Example 2:
# [04:34:44] [shane@Xion:~]$ enta-central-checker -a
# Central Number: 5 (LNS: m.dsl.enta.net)
# Expected Speed: 7.2Mbps (Green - Less than 600Mb)
# [04:34:45] [shane@Xion:~]$
#

# Show extended Information?
EXTENDED=${1}
# or Always show extended information
# EXTENDED="-a"

# Where does the list of centrals start in this file?
STARTLINE=`grep -n "^#### CENTRAL LIST ####$" $0`
STARTLINE=$((${STARTLINE%%:*} + 1))

# What traceroute should we use:
TR_NG=`which traceroute-nanog`
TR=`which traceroute`

# Where to traceroute to and find extended information
NOC="noc.enta.net"

# Hostname for LNS routers
LNS="dsl.enta.net"

# Use a temp file for noc page contents?
# If extended mode is really slow (more than a few seconds), set this to 1 to
# use an alternative method of getting the data from the noc.
USETEMP="0"

# Status' for colours
COL_Green="Less than 600Mb"
COL_Amber="Less than 622Mb (Almost Full)"
COL_Red="622Mb or Above"
COL_Black="Packet Loss Expected"

# Perform a traceroute to find the LNS, it is the first hop outside our local
# network, so we only need to look for 2 hops (our router, the LNS)
if [ "" != "${TR_NG}" ]; then
	CENTRALTRACE=`${TR_NG} -m 2 -q 1 ${NOC} | grep "${LNS}" | head -n 1`
elif [ "" != "${TR}" ]; then
	CENTRALTRACE=`${TR} -m 2 -q 1 ${NOC} | grep "${LNS}" | head -n 1`
else
	echo "Unable to traceroute, please install traceroute-nanog or traceroute in your PATH";
	exit 1;
fi;
# Get the name of the central. (This is separate from the TRACE incase more info
# is wanted at a later date.
CENTRALNAME=`echo ${CENTRALTRACE} | awk '{print $2}'`
# Check what Central number this name is
CENTRALNUMBER=`tail -n +${STARTLINE} $0 | grep ${CENTRALNAME}  | awk '{print $1}'`

# Extended information
# Don't try to get extended information for unknown centrals
if [ "${EXTENDED}" = "-a" -a "${CENTRALNUMBER}" != "Unknown" ]; then
	# Try to use wget (linux), curl (osx) or fetch (bsd)
	WGET=`which wget`
	CURL=`which curl`;
	FETCH=`which fetch`;
	TEMPFILE=""
	if [ "" != "${WGET}" -a "" != "${FETCH}" -a "" != "${CURL}" ]; then
		SPEED="Unknown"
		COLOUR="Unknown"
	elif [ "${USETEMP}" = "1" -a "`which mktemp`" != "" ]; then
		TEMPFILE=`mktemp`
		if [ "" != "${WGET}" ]; then
			${WGET} -q -O ${TEMPFILE} http://${NOC}/
		elif [ "" != "${CURL}" ]; then
			PAGE=`${CURL} -s -o ${TEMPFILE} http://${NOC}/`
		elif [ "" != "${FETCH}" ]; then
			PAGE=`${FETCH} -q -o ${TEMPFILE} http://${NOC}/`
		fi
	else
		if [ "" != "${WGET}" ]; then
			PAGE=`${WGET} -qO- http://${NOC}/`
		elif [ "" != "${CURL}" ]; then
			PAGE=`${CURL} http://${NOC}/`
		elif [ "" != "${FETCH}" ]; then
			PAGE=`${FETCH} -o - http://${NOC}/`
		fi
	fi;
	
	# Don't overwrite existing values
	if [ "" = "${COLOUR}" ]; then
		if [ "" = "${TEMPFILE}" ]; then
			LINE=`echo ${PAGE} | grep pipe-status`
		else
			LINE=`cat ${TEMPFILE} | grep pipe-status`
			rm -Rf ${TEMPFILE}
		fi;
		COLOUR=`echo ${LINE} | sed -r 's/(.*)Central '${CENTRALNUMBER}'(.*?)alt="(.+?)" tit(.*?)Expected performance ([^<]*)<.*/\3/g'`
		SPEED=`echo ${LINE} | sed -r 's/(.*)Central '${CENTRALNUMBER}'(.*?)alt="(.+?)" tit(.*?)Expected performance ([^<]*)<.*/\5/g'`
	fi
else
	SPEED="Unknown"
	COLOUR="Unknown"
fi;

# Echo the information!
echo "Central Number: ${CENTRALNUMBER} (LNS: ${CENTRALNAME})"

if [ "${EXTENDED}" = "-a" ]; then
	if [ "${COLOUR}" != "Unknown" ]; then
		# Haxy, very haxy.
		VAR=$`echo COL_${COLOUR}`
		STATUS=${COLOUR}" - "`eval echo ${VAR}`
	else
		STATUS=${COLOUR}
	fi;
	echo "Expected Speed: ${SPEED} (${STATUS})"
fi;

# Stop bash trying to execute the central list as commands.
exit 0;
# List of centrals follows. (Accurate as of 29/10/08)
#### CENTRAL LIST ####
# Central 1
1 t.dsl.enta.net 78.33.38.2
1 x.dsl.enta.net 78.33.38.6

# Central 2
2 b.dsl.enta.net 84.45.242.67
2 c.dsl.enta.net 84.45.242.68

# Central 3
3 e.dsl.enta.net 87.127.229.34
3 f.dsl.enta.net 87.127.229.35

# Central 4
4 r.dsl.enta.net 84.45.242.71
4 s.dsl.enta.net 84.45.242.72

# Central 5
5 m.dsl.enta.net 87.127.229.37
5 n.dsl.enta.net 87.127.229.38

# Central 6
6 y.dsl.enta.net 78.33.38.10
6 z.dsl.enta.net 78.33.38.14

# Central 7

# Central 8

# 21CN
21CN q.dsl.enta.net 87.127.229.9
21CN lns01.the.dsl.enta.net 78.33.38.26

# Unknown Centrals
# dig a.dsl.enta.net | egrep "^[^;].*IN.*A" | grep dsl | awk '{print "Unknown",$1,$5}'
Unknown a.dsl.enta.net 84.45.242.66
Unknown d.dsl.enta.net 84.45.242.69
Unknown g.dsl.enta.net 87.127.229.4
Unknown h.dsl.enta.net 87.127.229.5
Unknown i.dsl.enta.net 87.127.229.6
Unknown j.dsl.enta.net 87.127.229.7
Unknown k.dsl.enta.net 87.127.229.8
Unknown l.dsl.enta.net 87.127.229.36
Unknown o.dsl.enta.net 87.127.229.39
Unknown p.dsl.enta.net 84.45.242.70
Unknown u.dsl.enta.net 87.127.229.11
Unknown v.dsl.enta.net 87.127.229.12
Unknown w.dsl.enta.net 87.127.229.13