Pondering how to lock down a few bits to just an IP or two I hacked together this awful bit of bash:
#!/bin/bash
function valid_ip()
{
local ip=$1
local stat=1
if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
OIFS=$IFS
IFS='.'
ip=($ip)
IFS=$OIFS
[[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \
&& ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
stat=$?
fi
return $stat
}
HOME_IP=`host dyndnsname.dyndns-home.com|awk '{print $4};'`
if valid_ip $HOME_IP; then
OLD_IP=`grep HOME_IP /home/user/public_html/blog/wp-admin/.htaccess|awk '{print $3}'`;
if [ $OLD_IP != $HOME_IP ]; then
sed -i -e "s/ [0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\} #HOME_IP/ $HOME_IP #HOME_IP/" \
/home/user/public_html/blog/wp-admin/.htaccess
echo "DNS Changed to $HOME_IP from $OLD_IP"
fi
fi
exit
So if you have a locked down .htaccess something like:
Satisfy any order deny,allow allow from 12.12.12.12 #HOME_IP deny from all
The above script will update it. Bung it in cron and hey presto. Most routers have options to update dyndns and other services to ensure your IP is current generic diovan.
One Response to DynDNS.org + Bash + Router == A tiny bit safer.