#!/usr/bin/env bash

int_ip=`ifconfig | grep -E "(inet\s)" | grep -v 127.0.0 | cut -d ' ' -f 10`
ext_ip=`wget -O - -o /dev/null https://ip.weba.ru/ip.php`

udata=`wget -O - -o /dev/null https://secure.weba.ru/balance.php`
money=`echo $udata | cut -d ';' -f 1`
usern=`echo $udata | cut -d ';' -f 2`
usrip=`echo $udata | cut -d ';' -f 3`
if [ ! -n $ext_ip ]
then
   ext_ip=$usrip
fi

echo -en "Start WEBA speedtest... "`date "+%Y-%m-%d %T"`"; $usern, $money RUB\n"
echo -en "  Internal IP: $int_ip\n"
echo -en "  External IP: $ext_ip\n\n"

if ! command -v iperf > /dev/null
then
  echo "No iperf found. Install iperf and try again."
else
  echo " ... Serv1 TCP"
  iperf -c iperf.weba.ru -i2 -b1G

  echo " ... Serv1 UDP"
  iperf -c iperf.weba.ru -i2 -b1G -u

  echo " ... Serv2 TCP"
  iperf -c iperf2.weba.ru -i2 -b1G

  echo " ... Serv2 UDP"
  iperf -c iperf2.weba.ru -i2 -b1G -u
fi

echo "Finished."
