Change IP

Home
Sign in Sign up

Code for Linux system. Everything handled locally.

Run this regularly on your linux system if you want to handle all the checking yourself locally. Note that this script is of no use without adding some action to it, so if you don't know what you are doing and understand the script, don't use this method.

            

            
#!/bin/bash
IPFILE="wan_ip.txt"
LAST_IP="-.-.-.-"

# Retrieve the current WAN IP
WAN_IP=$(wget -q -O - checkip.nerdur.com/text | grep -Po " [\d\.]+")

if [[ -f "$IPFILE" ]]; then
    LAST_IP=$(cat "$IPFILE")
    echo "Previous WAN IP was: $LAST_IP"
    if [[ "$LAST_IP" != "$WAN_IP" ]]; then
        echo "WAN IP Address has CHANGED to $WAN_IP since last checked."
        # DO SOMETHING
    fi
else
    echo "WAN IP first run is: $WAN_IP"
fi

cat <<EOM > "$IPFILE"
$WAN_IP
EOM