Skip to content

Instantly share code, notes, and snippets.

@smj10j
Forked from corny/dynv6.sh
Last active March 21, 2017 11:50
Show Gist options
  • Save smj10j/6730d6136eb206e9b9bc to your computer and use it in GitHub Desktop.
Save smj10j/6730d6136eb206e9b9bc to your computer and use it in GitHub Desktop.
OSX Version of a script to update IPv4 and IPv6 on http://dynv6.com
#!/bin/sh -e
##
## 03/03/2015
## Updates IPv4 and IPv6 on DynV6.com on OSX
## https://gist.github.com/smj10j/6730d6136eb206e9b9bc
## Original at https://gist.github.com/corny/7a07f5ac901844bd20c9
##
## Example call:
## token=<token> ./dynv6.sh <your dynv6 hostname>
##
## Read more: http://dynv6.com/hosts/1401/instructions
##
hostname=$1
device=$2
file=$HOME/.dynv6.addr6
[ -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
device="en0"
fi
address=$(ifconfig $device inet6 | grep -v " fd" | sed -n 's/.*inet6 \([0-9a-f:]\+\).*/\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 "$address" ]; then
echo "no ipv6 address found"
exit 1
fi
# address with netmask
current=$address/$netmask
if [ "$old" = "$current" ]; then
echo "ipv6 address unchanged"
echo "sending anyway in case ipv4 has changed"
# exit
fi
# send addresses to dynv6
$bin "http://dynv6.com/api/update?hostname=$hostname&ipv6=$current&ipv4=auto&token=$token"
# save current address
echo $current > $file
@perroud
Copy link

perroud commented Jan 13, 2017

Stephen, doesn't work here. Line 32, I guess. Here, DHCPv6-PD.

@steveharman
Copy link

mine neither for, apparently a different reason:

/dynv6.sh: line 18: [: /Volumes/Macintosh: binary operator expected

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