Enter a quick solution using Unix shell script and cron to schedule. Thanks to AntonioCS's GitHub post, he provided a good bash script, but did not work on the Mac. So, with a small modification, we are golden!
First problem, is the script doesn't do an update if the IP address doesn't change. So, I force a change, like this, to a dummy IP address:
#!/bin/bash
# No-IP uses emails as passwords, so make sure that you encode the @ as %40
USERNAME=--account name--
PASSWORD=--my password--
HOST=--my host name--
LOGFILE=logdir/noip.log
STOREDIPFILE=configdir/current_ip
USERAGENT="Simple Bash No-IP Updater/0.4 antoniocs@gmail.com"
if [ ! -e $STOREDIPFILE ]; then
touch $STOREDIPFILE
fi
NEWIP=1.1.1.1
STOREDIP=$(cat $STOREDIPFILE)
RESULT=$(curl -o "$LOGFILE" -s --user-agent "$USERAGENT" "https://$USERNAME:$PASSWORD@dynupdate.no-ip.com/nic/update?hostname=$HOST&myip=$NEWIP")
LOGLINE="[$(date +"%Y-%m-%d %H:%M:%S")] $RESULT"
echo $NEWIP > $STOREDIPFILE
echo $LOGLINE >> $LOGFILE
exit 0
Then, I use the No-IP DUC for Mac. I suppose I could get rid of the GUI, and use the modified AntonioCS script that gathers the current IP address instead, but this suffices nicely, and keeps a GUI up so I can always easily monitor the No-IP status. If we want, we can do something similar to get the real IP:
#!/bin/bash
# No-IP uses emails as passwords, so make sure that you encode the @ as %40
USERNAME=--account name--
PASSWORD=--my password--
HOST=--my host name--
LOGFILE=logdir/noip.log
STOREDIPFILE=configdir/current_ip
USERAGENT="Simple Bash No-IP Updater/0.4 antoniocs@gmail.com"
if [ ! -e $STOREDIPFILE ]; then
touch $STOREDIPFILE
fi
NEWIP=$(curl http://icanhazip.com/)
STOREDIP=$(cat $STOREDIPFILE)
if [ "$NEWIP" != "$STOREDIP" ]; then
RESULT=$(curl -o "$LOGFILE" -s --user-agent "$USERAGENT" "https://$USERNAME:$PASSWORD@dynupdate.no-ip.com/nic/update?hostname=$HOST&myip=$NEWIP")
LOGLINE="[$(date +"%Y-%m-%d %H:%M:%S")] $RESULT"
echo $NEWIP > $STOREDIPFILE
else
LOGLINE="[$(date +"%Y-%m-%d %H:%M:%S")] No IP change"
fi
echo $LOGLINE >> $LOGFILE
exit 0
No comments:
Post a Comment