#!/bin/sh -e # based on https://gist.github.com/corny/7a07f5ac901844bd20c9 hostname=k9982874.dns.navy device=ppp0 token= v4_file=/tmp/${hostname} [ -e $v4_file ] && old=`cat $v4_file` if [ -z "$hostname" -o -z "$token" ]; then echo "Usage: token= $0 your-name.dynv6.net [device]" exit 1 fi if [ -n "$device" ]; then device="dev $device" fi v4_address=$(ip -4 addr list $device | grep "global" | sed -n 's/.*inet \([0-9.]\+\).*/\1/p' | head -n 1); echo $v4_address 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 "$v4_address" ]; then echo "no IPv4 address found" exit 1 fi current=$v4_address if [ "$old" = "$current" ]; then # when running via cron we do not need that kind of verbosity. # echo "IPv4 address unchanged" exit fi echo "new ipv4 address detected ${v4_address}, updating" # send addresses to dynv6 $bin "http://ipv4.dynv6.com/api/update?hostname=$hostname&ipv4=$v4_address&token=$token" # save current address echo $current > $v4_file