Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Update script for dynv6.com to set IPv6 prefix (address)
#!/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 "https://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
@thomasschaeferm
Copy link
Author

thomasschaeferm commented Apr 17, 2019

At DS-Lite it is useless and harmful to set A-records. They point to invalid ip addresses. Mostly to non responsive AFTR/CGN-Gateways.
Also https for updates is useful.

@Reihard
Copy link

Reihard commented Aug 20, 2019

Hello, can I have a more detailed tutorial about the first 10 lines? Do I fill in $1 and $2 manually and add a line to token?

@thomasschaeferm
Copy link
Author

thomasschaeferm commented Aug 20, 2019

Read line 8. You don't fill in $1 and $2 manually. You just call the script with the token as environment variable and the host name as first argument and the device name as a second argument, if you need it.
This is just a fork with some useful changes for hosts connected to the internet via ds-lite.
The first 10 lines are unchanged, so you should ask your questions here:
https://gist.github.com/corny/7a07f5ac901844bd20c9

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