Skip to content

Instantly share code, notes, and snippets.

@ripples-alive
Forked from corny/dynv6.sh
Last active April 14, 2016 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ripples-alive/8f80393a6b8de1637a26676621793daa to your computer and use it in GitHub Desktop.
Save ripples-alive/8f80393a6b8de1637a26676621793daa 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
v6_file=/tmp/.dynv6-"$hostname".addr6
v4_file=/tmp/.dynv6-"$hostname".addr4
[ -e $v6_file ] && v6_old=`cat $v6_file`
[ -e $v4_file ] && v4_old=`cat $v4_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
v6_address=$(ip -6 addr list scope global $device | grep -v " fd" | sed -n 's/.*inet6 \([0-9a-f:]\+\).*/\1/p' | head -n 1)
v4_address=$(ip -4 addr list scope global $device | grep -v " fd" | sed -n 's/.*inet \([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 "$v6_address" ]; then
echo "no IPv6 address found"
else
# address with netmask
v6_current=$v6_address/$netmask
if [ "$v6_old" = "$v6_current" ]; then
echo "IPv6 address unchanged"
else
# send addresses to dynv6
$bin "http://dynv6.com/api/update?hostname=$hostname&ipv6=$v6_current&token=$token"
# save current address
echo $v6_current > $v6_file
fi
fi
if [ -z "$v4_address" ]; then
echo "no IPv4 address found"
else
v4_current=$v4_address
if [ "$v4_old" = "$v4_current" ]; then
echo "IPv4 address unchanged"
else
# send addresses to dynv6
$bin "http://ipv4.dynv6.com/api/update?hostname=$hostname&ipv4=$v4_current&token=$token"
# save current address
echo $v4_current > $v4_file
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment