Skip to content

Instantly share code, notes, and snippets.

@PotcFdk
Last active December 5, 2017 19:54
Show Gist options
  • Save PotcFdk/ba413f308f48eb220bf4032fd709e213 to your computer and use it in GitHub Desktop.
Save PotcFdk/ba413f308f48eb220bf4032fd709e213 to your computer and use it in GitHub Desktop.
FRITZ!Box Callmonitor shell script
#!/bin/bash
OLDIFS=$IFS
ask() {
# http://djm.me/ask
while true; do
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
prompt="y/N"
default=N
else
prompt="y/n"
default=
fi
# Ask the question - use /dev/tty in case stdin is redirected from somewhere else
read -p "$1 [$prompt] " REPLY </dev/tty
# Default?
if [ -z "$REPLY" ]; then
REPLY=$default
fi
# Check if the reply is valid
case "$REPLY" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac
done
}
function trim {
echo -n "$@" | sed 's/^[[:space:]]*(.+)[[:space:]]*$/\\1/'
}
while [ true ]; do # Main check Loop
echo "Connecting..."
nc 192.168.2.1 1012 | while read line; do
declare -a info
echo -n "* "
IFS=';'
read -r -a info <<< "$line"
time=${info[0]}
cmd=${info[1]}
connection_id=${info[2]}
echo -n "$time " | tee -a $LOGFILE
if [ $cmd = "RING" ]; then
caller=${info[3]}
dest=${info[4]}
method=${info[5]}
echo "[RING] incoming from $caller to us, $dest, via $method" | tee -a $LOGFILE
elif [ $cmd = "CALL" ]; then
msn=${info[3]}
src=${info[4]}
dest=${info[5]}
method=${info[5]}
echo "[CALL] outgoing to $dest from us, $src->$msn, via $method" | tee -a $LOGFILE
elif [ $cmd = "CONNECT" ]; then
msn=${info[3]}
dest=${info[4]}
echo "[CONNECT] established connection with $dest" | tee -a $LOGFILE
elif [ $cmd = "DISCONNECT" ]; then
duration=${info[3]}
echo "[DISCONNECT] connection terminated" | tee -a $LOGFILE
else
>&2 echo "Unknown command: $line (this shouldn't happen)"
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment