Skip to content

Instantly share code, notes, and snippets.

@pulsar256
Forked from corny/dynv6.sh
Last active January 11, 2022 09:58
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save pulsar256/42313fcb2d3ae805805f to your computer and use it in GitHub Desktop.
Save pulsar256/42313fcb2d3ae805805f to your computer and use it in GitHub Desktop.
Update script for dynv6.com to set your IPv4 address
#!/bin/sh -e
# based on https://gist.github.com/corny/7a07f5ac901844bd20c9
hostname=$1
device=$2
v4_file=$HOME/.${hostname}.dynv6.addr4
[ -e $v4_file ] && old=`cat $v4_file`
if [ -z "$hostname" -o -z "$token" ]; then
echo "Usage: token=<your-authentication-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);
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
@nephilim75
Copy link

nephilim75 commented Aug 11, 2017

Hej hej,

when I used this script my internal IP was submitted to dynv6. So I updated line 20:

v4_address=$(curl http://my.ip.fi);

Once I did it this way, my external IPv4 was sent properly. Indeed, curl needs to be installed on server for that reason and network needs to be fully established.

Kind regards
//neph

@superneroes
Copy link

Hello,

I get the error promt "/bin/sh: 0: Illegal option -" executing the script on my Raspberry Pi.
How can I fix this?

@kuzyaka
Copy link

kuzyaka commented Oct 13, 2019

Hej hej,

when I used this script my internal IP was submitted to dynv6. So I updated line 20:

v4_address=$(curl http://my.ip.fi);

Once I did it this way, my external IPv4 was sent properly. Indeed, curl needs to be installed on server for that reason and network needs to be fully established.

Kind regards
//neph

author considered manual change from "global" to "ppp0" on line 20 in linked article https://odnkz.blogspot.com/2018/09/ddns-xiaomi-mi-3g-router-padavan.html

Using curl is not correct because primary IP source is local device. When you use "curl http://my.ip.fi" you get the last registered IP address on the DynDNS service. This contradicts the purpose of the script - to inform the DynDNS service of the new local IP address.

@rfuehrer
Copy link

I want to thank you (@pulsar256, @nephilim75). Thanks to your efforts, I have created a docker image that can be used to update multiple zones of Dynv6. Alternatively, the included scripts can be used separately or in a combined version of the script. However, I have taken the approach to leave the script unchanged as described here (to be updateable).

https://hub.docker.com/r/rfuehrer/dynv6-updater

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