Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

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

This comment has been minimized.

Copy link

superneroes commented Mar 30, 2019

Hello,

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

@kuzyaka

This comment has been minimized.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.