Skip to content

Instantly share code, notes, and snippets.

@Geofferey
Created May 2, 2021 01:49
Show Gist options
  • Save Geofferey/e784b7dd378029056fd9ccea8dcba531 to your computer and use it in GitHub Desktop.
Save Geofferey/e784b7dd378029056fd9ccea8dcba531 to your computer and use it in GitHub Desktop.
#!/bin/sh -e
PATH=$PATH:/usr/sbin:/usr/bin
hostname=somehost@v6.army
device=$2
token=blahblah
file=/tmp/.dynv6.addr6
bind_ip=192.0.0.1
update4="http://ipv4.dynv6.com/api/update?hostname=$hostname&ipv4=auto&token=$token"
update6="http://dynv6.com/api/update?hostname=$hostname&ipv6=auto&token=$token"
[ -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 [ -z "$device" ]; then
if ifconfig rmnet_data0 |grep -q -w "inet"; then
interface=rmnet_data0
elif ifconfig rmnet_data1 |grep -q -w "inet"; then
interface=rmnet_data1
elif ifconfig rmnet_data2 |grep -q -w "inet"; then
interface=rmnet_data2
elif ifconfig rmnet_data3 |grep -q -w "inet"; then
interface=rmnet_data3
fi
fi
if [ -n "$device" ]; then
device="dev $device"
fi
echo
echo $interface
echo
address=$(ip -6 addr list scope global dev $interface | grep -v " fd" | sed -n 's/.*inet6 \([0-9a-f:]\+\).*/\1/p' | head -n 1)
echo $address
echo
#cat $file || true
#exit
if [ -e /usr/bin/wget ]; then
bin="wget -O-"
else
echo "wget not found"
exit 1
fi
if [ -z "$address" ]; then
echo "no IPv6 address found"
exit 1
fi
# address with netmask
dns_addr=$(nslookup hd1905.v6.army |grep Address |tail -n1 | cut -d ' ' -f2)
echo $dns_addr
echo
#echo $current
#echo $address
if [ "$address" != "$dns_addr" ]; then
echo "IPv6 address changed"
#exit
# send addresses
if $bin "http://dynv6.com/api/update?hostname=$hostname&ipv6=$address&token=$token"; then
# save current address
echo $current > $file
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment