Previously I posted a script I used to update my RADIUS server IP (dynamic) on my RADIUS client whenever the IP changes. It was working well until about an hour ago, when apparently CloudFlare’s API endpoint died and the NEW_IP I was getting was only the client’s due to grepping the API response for an IP address, which the 502 page unhelpfully provides (in this case). For now I’m just fixing it with a simple check: get my client’s IP, compare it with the response and if they are the same, assume the CloudFlare API is down. I should probably implement more checks eventually…

MY_IP=$(wget -O - -q
NEW_IP=$(curl --silent<your-zone-id>/dns_records/<radius-server-hostname> \  
-H 'X-Auth-Email: <cloudflare-email>' \
-H 'X-Auth-Key: <cloudflare-key>' \
-H 'Accept: application/json' | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')
if [ "$NEW_IP" == "$MY_IP" ]; then
        logger "radius-update: CloudFlare API down"
OLD_IP=`nvram get wl0_radius_ipaddr`

if [ "$NEW_IP" == "$OLD_IP" ]; then  
        logger "radius-update: IP unchanged"

nvram set wl0_radius_ipaddr="$NEW_IP"  
nvram commit  
logger "radius-update: IP set to $NEW_IP, restarting wireless"