ydns / bash-updater

YDNS Bash Updater Script
GNU General Public License v3.0
80 stars 43 forks source link

Using ident.me for private networks #53

Open randyramig opened 3 years ago

randyramig commented 3 years ago

Like many people, I have an ISP (Comcast/Xfinity) where my internal network is private behind the public IP address that the ISP provides. The script isn't useful in its current form because it is obtaining the IP address of the local machine and for that local machine is a non-routable private address. Below is what I did, I did not have permissions to push a topic branch and create a PR.

I updated the script as follows for my needs:

  1. Added the -r option. This takes an argument in the form of "v4" or "v6" which maps to using v4.ident.me or v6.ident.me servers used to look up the public facing IP address for my network.
identme_ver=

while getopts "hH:i:p:r:u:vV" opt; do
        case $opt in
                h)
                        usage
                        ;;

                H)
                        custom_host="$custom_host $OPTARG"
                        ;;

                i)
                        local_interface_addr=$OPTARG
                        ;;

                p)
                        YDNS_PASSWD=$OPTARG
                        ;;

                u)
                        YDNS_USER=$OPTARG
                        ;;

                r)
                        identme_ver=$OPTARG
                        ;;

                v)
                        show_version
                        ;;

                V)
                        verbose=1
                        ;;
        esac
done
  1. If -r [v4|v6] is specified, use ident.me for the current_ip lookup:
if [ "$identme_ver" != "" ]; then
        # Obtain current address via ident.me
        current_ip=$(curl -s ${identme_ver}.ident.me)
elif [ "$local_interface_addr" != "" ]; then
        # Retrieve current local IP address for a given interface

    if hash ip 2>/dev/null; then
        current_ip=$(ip addr | awk '/inet/ && /'${local_interface_addr}'/{sub(/\/.*$/,"",$2); print $2}')
    fi
fi