#!/bin/sh
#
# porttwiddlenotify
# Play a sound on internal speaker when someone tries to connect to a
# blocked port.
# Ports below 10000 produce a sound between 20 and 5020 Hz
# all higher ports are squeezed between 5020 and 10061 Hz
#
# by Andreas Klingler 2002

duration=30
kernellog=$1

beep()
{
	freq=$1
	dur=$2

	echo -e "\\033[10;$freq]\\033[11;$dur]\\007\\033[10]\\033[11]" >/dev/console
}


tail -f $kernellog | grep 'Packet log' | \
	while  read line
	do
		port=`echo $line | cut -f13 -d" " | cut -f2 -d":"`

		if [ $port -lt 10000 ]
		then 
			tone=`expr $port / 2 + 20`
		else
			tone=`expr $port / 13 + 5000 + 20`
		fi
		beep $tone $duration
	done
