CURL skript för att uppdatera dynamisk ip
Hej, jag funderar över en sak. Dvs har lite problem.
Jo jag har ju min DNS på Loopia och jag hittade detta skript här nedan som ska fixa detta. Och jag köpt en app som ska köra detta ''Lingon3'' Men jag funderar lite vad jag ska fylla i här på detta.
Det står vilken domän man vill uppdatera 'hostname=example.example.org' och där fyller jag i min domän. Sedan har vi logg in detaljer 'login:pass' där skriver jag förmodligen mitt användarnamn och lösenord.
Men sedan har jag lite problem, räcker detta som jag har skrivit hittills? Eller måste jag fylla i den ip som jag har vid tillfället någonstans? Eller något mera för att detta ska fungera. Är ny på detta.
#!/bin/sh
# First the adress we want to update, CHANGE THIS to your address
hostname=example.example.org
# Second the login:pass we'll use, CHANGE THIS to your login and password
cred='login:pass'
# Get IP adress from Loopia
myip=`curl -s dns.loopia.se/checkip/checkip.php | sed 's/^.*: \([^<]*\).*$/\1/'`
# Check that we actually got anything
if [ x"$myip" = x ]
then
echo Failed to get IP. Exiting.
exit 255
fi
# Check that we actually got anything more or less sane
# Should really check that it's actually is an ipadress
# on the format 1.2.3.4 where each number is less than 256.
fmyip=`echo "$myip" | tr -cd '0-9.'`
if [ x"$fmyip" != x"$myip" ]
then
echo Failed to understand IP received: "$myip"
echo Exiting
exit 255
fi
# Check if we already set this ip-adress
# We should really check DNS but since there is no good
# general command line that works similar on most UNIX
# we can't rely on it.
tempdir="$TMP"
[ x"$tempdir" = x ] && tempdir="$TMPDIR"
[ x"$tempdir" = x ] && tempdir=/tmp
ipfile="$tempdir"/"$hostname".ip
if [ -r "$ipfile" ]
then
fmyip=`grep '^'"$myip"'$' "$ipfile"`
if [ x"$myip" = x"$fmyip" ]
then
#echo No change detected. Wont run update.
exit 0
fi
fi
# Store the IP for future updates
if [ -d "$tempdir" -a -w "$tempdir" ]
then
echo "$myip" > "$ipfile"
else
echo Warning, tempdir do not exist or is not writable: "$tempdir"
fi
# Base URL
burl=https://dns.loopia.se/XDynDNSServer/XDynDNS.php
# Extra options
eops='wildcard=NOCHG'
# Build URL
url="$burl"'?hostname='"$hostname"'&'myip="$myip"'&'"$eops"
curl -s --user "$cred" "$url"
echo