Skip to content

Instantly share code, notes, and snippets.

@PotcFdk
Last active December 5, 2017 19:54
Show Gist options
  • Select an option

  • Save PotcFdk/ba413f308f48eb220bf4032fd709e213 to your computer and use it in GitHub Desktop.

Select an option

Save PotcFdk/ba413f308f48eb220bf4032fd709e213 to your computer and use it in GitHub Desktop.

Revisions

  1. PotcFdk revised this gist May 13, 2016. 1 changed file with 86 additions and 1 deletion.
    87 changes: 86 additions & 1 deletion callmonitor.sh
    100644 → 100755
    Original file line number Diff line number Diff line change
    @@ -1 +1,86 @@
    #
    #!/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
  2. PotcFdk created this gist May 13, 2016.
    1 change: 1 addition & 0 deletions callmonitor.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    #