Update script for dynv6.com to set your IPv4 address and IPv6 prefix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
hostname=$1 | |
device=$2 | |
file=$HOME/.dynv6.addr6 | |
[ -e $file ] && old=`cat $file` | |
if [ -z "$hostname" -o -z "$token" ]; then | |
echo "Usage: token=<your-authentication-token> [netmask=64] $0 your-name.dynv6.net [device]" | |
exit 1 | |
fi | |
if [ -z "$netmask" ]; then | |
netmask=128 | |
fi | |
if [ -n "$device" ]; then | |
device="dev $device" | |
fi | |
address=$(ip -6 addr list scope global $device | grep -v " fd" | sed -n 's/.*inet6 \([0-9a-f:]\+\).*/\1/p' | head -n 1) | |
if [ -e /usr/bin/curl ]; then | |
bin="curl -fsS" | |
elif [ -e /usr/bin/wget ]; then | |
bin="wget -O-" | |
else | |
echo "neither curl nor wget found" | |
exit 1 | |
fi | |
if [ -z "$address" ]; then | |
echo "no IPv6 address found" | |
exit 1 | |
fi | |
# address with netmask | |
current=$address/$netmask | |
if [ "$old" = "$current" ]; then | |
echo "IPv6 address unchanged" | |
exit | |
fi | |
# send addresses to dynv6 | |
$bin "http://dynv6.com/api/update?hostname=$hostname&ipv6=$current&token=$token" | |
$bin "http://ipv4.dynv6.com/api/update?hostname=$hostname&ipv4=auto&token=$token" | |
# save current address | |
echo $current > $file |
I made a simple batch file script for my Windows need, hope it can help someone too.
You should use https
Made my shell script like this. Think it's leightweight and easy to read
#!/bin/bash
# dynDNS with dynV6 & ipv6 done right
# Initial values
newIpV6=$(ip -6 addr show scope global | grep inet6 | sed -e 's/^.*inet6 \([^ ]*\)\/.*$/\1/;t;d')
oldIpV6='No data in cachefile'
# Change these parameters as you want to
logfile=~/dynv6.log
cachefile=~/.dynv6cache
token=<your-token>
zone=<your-zone>
if [[ -f $cachefile ]]; then
oldIpV6=$(cat $cachefile)
fi
if [[ $newIpV6 != $oldIpV6 ]]; then
echo "$(date): Updating the DNS. Output can be found in ${logfile}"
echo "$(date): $(curl -k "https://dynv6.com/api/update?token=${token}&zone=${zone}&ipv6=${newIpV6}")" | tee -a $logfile
echo $newIpV6 > $cachefile
else
echo "$(date): IP did not Change. Skipping the update" | tee -a $logfile
fi
Use this as a cron job as often as you need and you should be good to go.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@tm-107 thanks for the script. While this did most of the work for me, I had to modify it to the following for it to work for my needs. For some reason auto was setting the IPV6 address to one that ended in
::
and was missing the last three characters of my address. I made some small modifications to use the current address, including the netmask.@tolshao and @andi34
curl https://api6.ipify.org
will actually return an IPV4 address, but only if you have disabled IPV6. I imagine that was what happened above.