User Tools

Site Tools


bash:cisco_phone_scan

A simple script I wrote to scan our IP phone range at work so I know which number is where (for my click-to-dial script). I don't have access to the callmanager, hence I'm doing it like this.

phonescan.sh
COUNT=10
TIMEOUT=5
# Range goes from 10-253
while [ $COUNT -lt 254 ]; do
	TMPOUT=`lynx -connect_timeout=$TIMEOUT -dump http://192.168.222.$COUNT 2> /dev/null | egrep "Phone DN|Host Name"`
	if [ ${#TMPOUT} -gt 30 ]; then
# Debug sheit (or whatever, shuddap! :D), output the time.
		echo -n "`date +%T` - "
		NUMBER=`echo $TMPOUT | grep "Phone DN" | awk {'print $6'}`
		HOST=`echo $TMPOUT | grep "Host Name" | awk {'print $3'}`
 
		if [ ${#NUMBER} -gt 2 ] && [ ${#HOST} -eq 15 ]; then
			echo "SUCCESS: IP: 192.168.222.$COUNT - Number: $NUMBER - Host: $HOST"
			mysql --user=PhoneScan --password=XXXXXXX_PASS --execute="INSERT INTO phonescan (host, number, country, lastip, lastupdate) VALUES ('$HOST', $NUMBER, 'DK', '192.168.222.$COUNT', NOW()) ON DUPLICATE KEY UPDATE number = $NUMBER, lastupdate = NOW(), lastip = '192.168.222.$COUNT', country = 'DK';" XXXXXXX_USER
		else
			echo "ERROR: IP: 192.168.222.$COUNT - Number: $NUMBER - Host: $HOST"
		fi
	fi	
 
	let COUNT=COUNT+1
done
bash/cisco_phone_scan.txt · Last modified: 2015/08/15 22:56 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki