Asterisk script for change externip
If gateway in lan is Mikrotik, and SIP ALG was enabled on it, this script is useless.
#!/bin/bash
#
log() {
echo `date +"%Y-%m-%d %H:%M:%S"` $@ >>$Log
}
Log=/var/log/asterisk/change_externalip.log
#
getIPUrl="http://smart-ip.net/myip"
configFile=/etc/asterisk/sip.conf
configIP=`grep externip /etc/asterisk/sip.conf | sed 's/;.*//' | grep -v ^$ | sed s/.*=\ *//`
#
#echo "ConfigIP =" $configIP
extIP=`curl -s $getIPUrl`
#echo "ExtIP =" $extIP
if [ "$configIP" != "$extIP" ]
then
log "Updating IP in /etc/asterisk/sip.conf from $configIP to $extIP"
sed -i "s/externip=$configIP/externip=$extIP/" $configFile
sed -i "s/externaddr=$configIP/externaddr=$extIP/" $configFile
log "Running asterisk sip reload"
/usr/sbin/asterisk asterisk -rx "sip reload"
fi
# end of file