Forum Replies Created
-
AuthorPosts
-
faximilian
MemberSorry for the delayed answer. The router has crashed a few days ago – actually I don’t know why. I have to wait until I have physical access.
With the existing log file I cannot give you more information about the kind of access. All I know is that they caused about 25kbit traffic. The router has been accessed from different locations on different days.
faximilian
MemberThe following script works well a a cron script
You only have to adapt the INTERFACE variable
#!/bin/sh
. /etc/kerbynet.conf
RESOLUTION=1.1.1.1
CHANGED=no
EXPIRED=no
SKIP=no
if [ "`cat $REGISTER/system/ddnsclient/Enabled 2>/dev/null`" != yes ] ; then
OLDHOST="$REGISTER/system/ddnsclient/OldHOST"
OLDIP="$REGISTER/system/ddnsclient/OldIP"
LASTUPDATE="$REGISTER/system/ddnsclient/LastUpdate"
STATUS="$REGISTER/system/ddnsclient/Status"
INTERFACE="ppp0"
CHECKIP_URL="`cat $REGISTER/system/ddnsclient/CheckIP`"
IP=`curl -G --interface $INTERFACE --retry 1 -s $CHECKIP_URL |egrep '[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}'|head -1|sed -r 's/.* ([0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}).*/1/'`
if ! echo $IP | egrep -q '^[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}$'; then
logger -t DDNS "ERROR: IP checker not available ($CHECKIP_URL)"
SKIP=yes
fi
PROVIDER="`cat $REGISTER/system/ddnsclient/Provider 2>/dev/null`"
HOST="`cat $REGISTER/system/ddnsclient/Host 2>/dev/null`"
[ -z "$HOST" ] && SKIP=yes
if [ "$HOST" != "`cat $OLDHOST 2>/dev/null`" ] ; then
CHANGED=yes
fi
if [ "$IP" != "`cat $OLDIP 2>/dev/null`" ] ; then
CHANGED=yes
fi
TIMESTAMP=`date +%s`
OLDTS="`cat $LASTUPDATE 2>/dev/null`"
if ! [ -z "$OLDTS" ] ; then
if [ "$(( TIMESTAMP - OLDTS ))" -gt 2073600 ] ; then
EXPIRED=yes
fi
fi
if [ "$PROVIDER" = ".OpenDNS" ] ; then
RESOLUTION=1.1.1.1
else
RESOLUTION=`host $HOST 2>/dev/null |egrep '[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}'|head -1|awk '{print $4}'`
fi
if [ "$IP" != "$RESOLUTION" ] ; then
CHANGED=yes
echo "WAITING TO BE UPDATED" > $STATUS
else
echo "UPDATED" > $STATUS
fi
if [ "$SKIP" != yes ] ; then
if [ "$CHANGED" == yes -o "$EXPIRED" == yes -o "$PROVIDER" = "OpenDNS" ] ; then
if [ "$CHANGED" != yes -a "$EXPIRED" == yes ] ; then
logger -t DDNS "WARNING: Update is needed to prevent $HOST expiration"
fi
if [ "$IP" != "$RESOLUTION" -o "$EXPIRED" == yes ] ; then
if [ "$PROVIDER" != "OpenDNS" ] ; then
logger -t DDNS "WAN IP=$IP $HOST=$RESOLUTION (Update is needed)"
else
logger -t DDNS "WAN IP=$IP"
fi
ERROR="/tmp/dyndns.err"
RESULT="/tmp/dyndns.out"
USERNAME="`$SCRIPTS/getkey /system/ddnsclient/Username`"
PASSWORD="`$SCRIPTS/getkey /system/ddnsclient/Password`"
logger -t DDNS "Dynamic DNS updating $HOST ($USERNAME)"
if [ "$PROVIDER" = "OpenDNS" ] ; then
OPT="--user $USERNAME:$PASSWORD"
CURL="https://updates.opendns.com/nic/update?"
elif [ "$PROVIDER" = "DynDNS" ] ; then
OPT="--user $USERNAME:$PASSWORD"
CURL="http://members.dyndns.org/nic/update?system=dyndns&hostname=$HOST&mx=$HOST"
else
# No-IP
OPT="--user $USERNAME:$PASSWORD"
CURL="http://dynupdate.no-ip.com/nic/update?hostname=$HOST&mx=$HOST"
fi
if ! curl -G --interface $INTERFACE --retry 1 --connect-timeout 15 -s -S -o "$RESULT" $OPT "$CURL" 2>"$ERROR" ; then
if grep -q "Authorization failed" "$ERROR" ; then
CURLERROR="Authorization failed. BAD Username/Password"
else
CURLERROR="Connectivity ERROR"
fi
else
CURLERROR=""
fi
if [ -z "$CURLERROR" ] ; then
logger -t DDNS "==> `cat $RESULT`"
if grep -q "!yours|notfqdn|abuse|nohost|badagent|badauth|badsys|dnserr|numhost|911|!donator" $RESULT ; then
echo "Disabled for fatal ERROR. Please check the logs" > $STATUS
logger -t DDNS "==> A fatal error occurs and the DDNS client is now disabled. Please solve the problem and enable the Dynamic DNS Client."
echo no > $REGISTER/system/ddnsclient/Enabled
else
echo "UPDATED" > $STATUS
echo $HOST > $OLDHOST
echo $IP > $OLDIP
echo $TIMESTAMP > $LASTUPDATE
fi
else
echo "$CURLERROR" > $STATUS
logger -t DDNS "ERROR:"
grep -v " => " "$ERROR" | logger -t DDNS
fi
fi
fi
fi
fi
faximilian
MemberNow I have tried to replace wget commands by curl commands. Additionally I added a variable called INTERFACE which should be defined by the GUI.
However, I don’t know how to test economically the script in zeroshell.
Could someone please help me to debug the code:
#!/bin/sh
. /etc/kerbynet.conf
sleep 35
RESOLUTION=1.1.1.1
while true ; do
CHANGED=no
EXPIRED=no
SKIP=no
if [ "`cat $REGISTER/system/ddnsclient/Enabled 2>/dev/null`" == yes ] ; then
OLDHOST="$REGISTER/system/ddnsclient/OldHOST"
OLDIP="$REGISTER/system/ddnsclient/OldIP"
LASTUPDATE="$REGISTER/system/ddnsclient/LastUpdate"
STATUS="$REGISTER/system/ddnsclient/Status"
INTERFACE="$REGISTER/system/ddnsclient/Interface"
CHECKIP_URL="`cat $REGISTER/system/ddnsclient/CheckIP`"
IP=`curl -G --interface $INTERFACE --retry 1 -s $CHECKIP_URL |egrep '[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}'|head -1|sed -r 's/.* ([0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}).*/1/'`
if ! echo $IP | egrep -q '^[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}$'; then
logger -t DDNS "ERROR: IP checker not available ($CHECKIP_URL)"
SKIP=yes
fi
PROVIDER="`cat $REGISTER/system/ddnsclient/Provider 2>/dev/null`"
HOST="`cat $REGISTER/system/ddnsclient/Host 2>/dev/null`"
[ -z "$HOST" ] && SKIP=yes
if [ "$HOST" != "`cat $OLDHOST 2>/dev/null`" ] ; then
CHANGED=yes
fi
if [ "$IP" != "`cat $OLDIP 2>/dev/null`" ] ; then
CHANGED=yes
fi
TIMESTAMP=`date +%s`
OLDTS="`cat $LASTUPDATE 2>/dev/null`"
if ! [ -z "$OLDTS" ] ; then
if [ "$(( TIMESTAMP - OLDTS ))" -gt 2073600 ] ; then
EXPIRED=yes
fi
fi
if [ "$PROVIDER" = ".OpenDNS" ] ; then
RESOLUTION=1.1.1.1
else
RESOLUTION=`host $HOST 2>/dev/null |egrep '[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}'|head -1|awk '{print $4}'`
fi
if [ "$IP" != "$RESOLUTION" ] ; then
CHANGED=yes
echo "WAITING TO BE UPDATED" > $STATUS
else
echo "UPDATED" > $STATUS
fi
if [ "$SKIP" != yes ] ; then
if [ "$CHANGED" == yes -o "$EXPIRED" == yes -o "$PROVIDER" = "OpenDNS" ] ; then
if [ "$CHANGED" != yes -a "$EXPIRED" == yes ] ; then
logger -t DDNS "WARNING: Update is needed to prevent $HOST expiration"
fi
if [ "$IP" != "$RESOLUTION" -o "$EXPIRED" == yes ] ; then
if [ "$PROVIDER" != "OpenDNS" ] ; then
logger -t DDNS "WAN IP=$IP $HOST=$RESOLUTION (Update is needed)"
else
logger -t DDNS "WAN IP=$IP"
fi
ERROR="/tmp/dyndns.err"
RESULT="/tmp/dyndns.out"
USERNAME="`$SCRIPTS/getkey /system/ddnsclient/Username`"
PASSWORD="`$SCRIPTS/getkey /system/ddnsclient/Password`"
logger -t DDNS "Dynamic DNS updating $HOST ($USERNAME)"
if [ "$PROVIDER" = "OpenDNS" ] ; then
OPT="--user $USERNAME:$PASSWORD"
CURL="https://updates.opendns.com/nic/update?"
elif [ "$PROVIDER" = "DynDNS" ] ; then
OPT="--user $USERNAME:$PASSWORD"
CURL="http://members.dyndns.org/nic/update?system=dyndns&hostname=$HOST&mx=$HOST"
else
# No-IP
OPT="--user $USERNAME:$PASSWORD"
CURL="http://dynupdate.no-ip.com/nic/update?hostname=$HOST&mx=$HOST"
fi
if ! curl -G --interface $INTERFACE --retry 1 --connect-timeout 15 -s -S -o "$RESULT" $OPT "$CURL" 2>"$ERROR" ; then
if grep -q "Authorization failed" "$ERROR" ; then
CURLERROR="Authorization failed. BAD Username/Password"
else
CURLERROR="Connectivity ERROR"
fi
else
CURLERROR=""
fi
if [ -z "$CURLERROR" ] ; then
logger -t DDNS "==> `cat $RESULT`"
if grep -q "!yours|notfqdn|abuse|nohost|badagent|badauth|badsys|dnserr|numhost|911|!donator" $RESULT ; then
echo "Disabled for fatal ERROR. Please check the logs" > $STATUS
logger -t DDNS "==> A fatal error occurs and the DDNS client is now disabled. Please solve the problem and enable the Dynamic DNS Client."
echo no > $REGISTER/system/ddnsclient/Enabled
else
echo "UPDATED" > $STATUS
echo $HOST > $OLDHOST
echo $IP > $OLDIP
echo $TIMESTAMP > $LASTUPDATE
fi
else
echo "$CURLERROR" > $STATUS
logger -t DDNS "ERROR:"
grep -v " => " "$ERROR" | logger -t DDNS
fi
fi
fi
fi
fi
sleep 304
done
faximilian
MemberThe second solution I would suggest is to add an option for IP resoulution in the NetBalancer settings: “Use interface XY on targeting an IP which is defined by the following domain name…”
faximilian
MemberHi redfive,
thanks for your answer.
The script you linked to uses the –bind-address option.
This is only a good idea if the interface WAN address is known to the router. If not, the script will fail. E. g., in my case I am using a connection to a second router as a WAN connection. wget –bind-address would simply not work here.
For this reason I would suggest to use curl instead of wget.
Regards,
faximilian
faximilian
MemberI would suggest to use
curl –interface $INTERFACE
instead of
wget
in the ddns updater script. This should solve the problem in a good way.
Dear Fulvio,
could you perhaps help with a solution.
Regards,
Fabian
faximilian
Memberin order to get the IP adress of the local interface you could use
IP=`ifconfig ppp0 | awk ‘/inet addr/{print substr($2,6)}’`
instead of the code below in your ddns2 script
# IP=`wget –timeout=15 -t 1 -O – -o /dev/null $CHECKIP_URL |egrep ‘[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}’|head -1|sed -r ‘s/.* ([0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}.[0123456789]{1,3}).*/1/’`
Actually this only a workaround.
REMARK: EVEN THIS IS NOT A WORKAROUND BECAUSE DYNDNS USES THE IP FROM WHICH THE COMPUTER CONNECTS TO THE SERVER AS THE DYNAMIC IP
I am still looking for a possibility to access a particular website (checkip.dyndns.com) through a defined interface while using NetBalancer. Defining a rule does not work because dyndns.com uses dynamic ip addresses for their servers…
-
AuthorPosts