#!/bin/bash

# VERSION=4
# CHANGES="Adjusted to new welcome-line."

if [ -z "${1}" ]; then
	echo "Usage: ${0} <command> [<timeout>]"
	exit 1
fi

ISGW_PORT=54322

if [ -z "${2}" ]; then
	ISGW_TIMEOUT=5
else
	ISGW_TIMEOUT=${2}
fi

isgw_ans_full=$(echo -ne "${1};q\r\n" | /bin/nc -q ${ISGW_TIMEOUT} localhost ${ISGW_PORT})
isgw_ans_stripped=$(expr match "${isgw_ans_full}" ".*beroNet VoIP Gateway Console (enter h for help, q to quit)\(.*\)Closing terminal")

echo -e "${isgw_ans_stripped}"
