Reply To: Multiple DynDns

Home Page Forums Network Management Networking Multiple DynDns Reply To: Multiple DynDns

#48754

Lightyear
Member

I currently have two dynamic IP connections, one ADSL and one 3G.
Ivan Baldo, fine programmer and friend extraordinaire, made a script so ZeroShell updates both dynamic IPs.
He called it ddns2.nuestro (we are Spanish speakers) and placed it in the /Database directory.
Then he added the following command to the ZeroShell preboot script:

cp -v /Database/ddns2.nuestro /root/kerbynet.cgi/scripts/ddns2

so ddns2.nuestro is what ZeroShell wil run when updating dynamic IPs.
It has worked without a glitch for more than 3 months now, and I think it is very easy to modify for more than 2 dyndns accounts, or for another DDNS service.
Here it goes:

#!/bin/sh

# Script made by Ivan Baldo to permit multiple dyndns IP updating in ZeroShell

Usuario=”your_dyndns_user_name”
Contrasena=”your_dyndns_password”
Host_PPP0=”http_address_of_dyndns_account_1″
Host_PPP1=”http_address_of_dyndns_account_2″

actualiza ()
{
Interfaz=”$1″
Host=”$2″
IP=$(ifconfig $Interfaz 2>/dev/null | awk ‘NR==2 {print $2}’ | grep ‘.*..*..*..*’ | cut -d: -f2)
touch /tmp/dyndns.ipviej.$Interfaz
IPViej=”$(cat /tmp/dyndns.ipviej.$Interfaz)”
Actualizar=”no”
if [ “$IP” != “” ]; then
if [ “$IP” != “$IPViej” ]; then
Actualizar=”si”
fi
fi
if [ “$Actualizar” = “no” ]; then
return
fi
if [ -e /tmp/dyndns.deshabilitado.$Interfaz ]; then
return
fi
logger -t DDNS “Actualizando $Host a $IP de interfaz $Interfaz.”
if wget “–bind-address=$IP” -t 3 -w 20 -o /tmp/dyndns.error.$Interfaz -O /tmp/dyndns.resultado.$Interfaz
“http://$Usuario:$Contrasena@members.dyndns.org/nic/update?system=dyndns&hostname=$Host&mx=$Host&myip=$IP”
then
logger -t DDNS “==> $(cat /tmp/dyndns.resultado.$Interfaz)”
if grep -q “!yours|notfqdn|abuse|nohost|badagent|badauth|badsys|dnserr|numhost|911|!donator”
/tmp/dyndns.resultado.$Interfaz
then
logger -t DDNS “==> Hubo un error reportado por DynDNS, luego de solucionar el problema borre el archivo /tmp/dyndns.deshabilitado.$Interfaz!”
touch /tmp/dyndns.deshabilitado.$Interfaz
else
echo “$IP” >/tmp/dyndns.ipviej.$Interfaz
fi
else
logger -t DDNS “==> Error al conectarse con DynDNS:”
grep -v ” => ” /tmp/dyndns.error.$Interfaz | logger -t DDNS
fi
}

while true; do
actualiza ppp0 $Host_PPP0
actualiza ppp1 $Host_PPP1
sleep 60
done

Unfortunately, the forum editor does not allow script formatting. I hope it is readable all the same.
I believe also it’s easy to translate the Spanish parts if need be, but in any case I will be following this thread so feel free to ask for translation.

I hope I didn’t break any forum rule copying the script here, but I feel it really can be of help to someone, and I do not have any place to hang it for downloading πŸ™ .
ZeroShell rules! πŸ˜€