Home DNS Service Mail Service Web Service Logout
Message Center Public Forum DollarDNS News Options
Public Forum | Topic
Welcome Guest!
NAT-PMP update script for Mac people with Airport Extreme routers
darrinsmart
Member
Created Nov 21, 2009 15:15

Hi everyone, if you happen to be using a Airport router, here is a little shell script that will monitor changes to the public IP address and do a RFC 2136 dynamic IP address update. Just replace HOST/KEY/SECRET at the top of the script.

You can save this as dns-update.command, make it executable, and set it as one of your mac's startup items.


#!/bin/sh

# Shell script to monitor Airport's public IP address and
# update the dollardns server dynamically.

HOST=mydynamichostname.example.com
KEY=mykey.example.com
SECRET=dollardns-supplied-secret
SERVER=ns1.dollardns.net
TTL=1800
DELAY=30

# Print out public IP address every time it changes. Filter out
# non-public IP resonses and null responses (when router not connected to net)
get_public_ip()
{
dns-sd -X \
| egrep --line-buffered -o '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' \
| egrep --line-buffered -v '^(10\.|192.168\.|0.0.0.0)'
}

# Given a single IP address, talk to the DNS server and update it's A record
update_dyndns()
{
ip=$1

# Add a short delay here. Just to make sure the router and upstream
# connection have settled down.

echo "IP address update in $DELAY seconds"
sleep $DELAY

/bin/echo -n "Updating $HOST to $ip.."
printf "server $SERVER\nupdate delete $HOST A\nupdate add $HOST $TTL A $ip\nsend\n" \
| nsupdate -y${KEY}:${SECRET}
echo " Done."

}

# The script can be executed two ways. If run with
# a single argument, it updates the server using that IP address.
# With no arguments, it will
# monitor dns-sd for IP address changes and recursively execute itself to
# update the IP address.
if [ x"$1" = "x" ]; then
echo
echo NAT-PMP based RFC 2136 updater
echo Darrin Smart 2009
echo
get_public_ip | xargs -o -n1 $0
else
update_dyndns $1
fi




Dave Clark
Administrator
Created Nov 28, 2009 09:39
nifty.


Dave Clark [email] [irc chat]
DollarDNS Services