Broadvoice – Fastest proxy switcher for asterisk.

#!/bin/bash

curhip=(`cat /etc/hosts | grep sip.broadvoice.com | awk ‘{ print $1 }’`)
echo “Current IP: $curhip”

chkip=”(`ping -c 2 sip.broadvoice.com`)”
curiplow=(`echo $chkip | grep PING | grep -Eo ‘\b[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\b’ | uniq`)
curlow=(`echo $chkip | grep -o ‘time\s[0-9]\+[^ms]’ | awk ‘{ print $2 }’`)

function getnewlow {
echo “Testing: $1″
chkip=”(`ping -c 2 $1`)”
curip=(`echo $chkip | grep PING | grep -Eo ‘\b[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\b’ | uniq`)
curnum=(`echo $chkip | grep -o ‘time\s[0-9]\+[^ms]’ | awk ‘{ print $2 }’`)

if [ $curnum ] && [ $curlow -gt $curnum ]
then
curiplow=$curip
curlow=$curnum
fi
}

getnewlow proxy.nyc.broadvoice.com
getnewlow proxy.lax.broadvoice.com
getnewlow proxy.dca.broadvoice.com
getnewlow proxy.mia.broadvoice.com
getnewlow proxy.atl.broadvoice.com
getnewlow proxy.chi.broadvoice.com
getnewlow proxy.bos.broadvoice.com

echo “—————-”
echo $curlow
echo $curip
echo “—————-”

if [ $curhip ] && [ $curip != $curhip ]
then
echo “Faster IP Found…”
perl -pi -e ‘s/$curhip/$curip/g’ /etc/hosts
asterisk -rx ‘sip reload’
fi

, , , ,

No comments yet.

Leave a Reply

*

Powered by recycled bites and bytes.