Update einer dynamischen IP von afraid.org

Eine quick&dirty Methode zum Updaten eines DynDNS-Eintrags von afraid.org

die Idee kam von folgenden Beitrag auf stackoverflow.com

dynamischer.hostname.com ist halt auf den Eigenen zu ändern, sowie die eigene webupdate-url von afraid.org einzutragen.
Hier steht wie’s geht.

Das script am besten nach /usr/local/bin, falls man das hosts-file nicht updaten will|muß sollte es im usercontext (also nicht als root;-) ) laufen.

#!/bin/bash
# Get the dynamic IP (dirty, I know)

#disable echo http://stackoverflow.com/a/5973558
echo() { :; }

#oldip
IP=`host -t a dynamischer.hostname.com | perl -nle '/((?:\d+\.?){4})/ && print $1' | head -n1`  

#real IP
IPR=`wget http://ipinfo.io/ip -qO -` 

echo $IP
echo $IPR

#teste ob die external IP sich geändert hat & Update the hosts file
if [ "$IP" != "$IPR" ] ; then
    echo "change detected"
    curl -k http://freedns.afraid.org/dynamic/update.php?***webupdateurl*** 
    IPN=`host -t a dynamischer.hostname.com | perl -nle '/((?:\d+\.?){4})/ && print $1' | head -n1`
    if [ "$IP" == "$IPN" ] ; then
       echo "Sucess update dns-entry dynamischer.hostname.com"

       #uncomment the next lines to update hosts file     
       #grep -v dynamischer.hostname.com /etc/hosts > /tmp/hosts
       #echo "$IP dynamischer.hostname.com" >> /tmp/hosts
       #cp /tmp/hosts /etc/hosts

    else
       echo "something went terrible wrong, maybe offline"
    fi

else
    echo "no change"
fi

Automatisierung per cronjob


*/5 * * * * /usr/local/bin/update_dynip > /dev/null 2>&1

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.