Skip to content

Instantly share code, notes, and snippets.

@pd12bbf7608ae1
Created August 15, 2020 07:52
Show Gist options
  • Save pd12bbf7608ae1/43e1dd78e99c56b509101b83bfc6e156 to your computer and use it in GitHub Desktop.
Save pd12bbf7608ae1/43e1dd78e99c56b509101b83bfc6e156 to your computer and use it in GitHub Desktop.
he.net ddns
#!/bin/bash
token="token"
hostname="exmple.example.com"
device="eth0"
file=$HOME/.iphistory_henet
[ -e $file ] && old=`cat $file`
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 [ -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
result=$(curl "https://dyn.dns.he.net/nic/update" -d "hostname=$hostname1" -d "password=$token" -d "myip=$current")
if [ "$?" != "0" ]; then
exit
fi
result=$(echo "$result" | grep -c bad)
if [ "$result" != "0" ]; then
exit
fi
# save current address
echo $current > $file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment