Skip to content

Instantly share code, notes, and snippets.

@gocarlos
Forked from corny/dynv6.sh
Created August 25, 2016 08:46
Show Gist options
  • Save gocarlos/b84f601e3660748f7c1e10cf862a00d0 to your computer and use it in GitHub Desktop.
Save gocarlos/b84f601e3660748f7c1e10cf862a00d0 to your computer and use it in GitHub Desktop.
Update script for dynv6.com to set your IPv4 address and IPv6 prefix
#!/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
@gocarlos
Copy link
Author

gocarlos commented Nov 7, 2016

from @bertenvdb

Click on the 'raw' button on the top right-hand side of the above script, and copy/paste the entire code to a file dynv6.sh in your home directory.
Make the script executable
chmod +x dynv6.sh
Execute the script using the link found on the 'instructions' tab of your host on dynv6.net
token=Q-4pOEg4UyAuq8mySeWgAJfiGWXHtQ ./dynv6.sh test123x.dynv6.net
Optionally have cron execute the script every 5 mins or so. Nothing will be sent if your IP hasn't changed.

crontab -e to open your editor
Add the line */5 * * * * token=Q-4pOEg4UyAuq8mySeWgAJfiGWXHtQ ./dynv6.sh test123x.dynv6.net
save and close editor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment