Skip to content

Instantly share code, notes, and snippets.

@z3nth10n
Last active February 17, 2022 18:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save z3nth10n/c00ac1f3b6973ceb2cc1dad2b8444f6e to your computer and use it in GitHub Desktop.
Save z3nth10n/c00ac1f3b6973ceb2cc1dad2b8444f6e to your computer and use it in GitHub Desktop.
Updates your dynamic IP using name.com services

Name.com IP updater

Updates your dynamic IP using name.com services

This is useful when your have a local server in home.

Setup (3 steps)

Linq.py uses Python 2.7+ be careful!

Install dependencies

$ apt install curl python

Script execution

Then, download both shell scripts, then you just to execute this script once with this:

$ bash curl.sh <instance_id> <your_username> <your_password> <server> <hostname> (debug)

  • Note: use optional debug param to know state of the execution.

In my case:

$ bash curl.sh home_network z3nth10n blablabla z3nth10n.net home $ bash curl.sh vpn_server z3nth10n blablabla z3nth10n.net vpn_server

Note: If you need to know your API token, please review this link.

This will update the A record for my home subdomain in name.com:

image

Crontab

Then, configure a Cron task:

$ crontab -e

Append this line:

@hourly /<path>/curl.sh <instance_id>

In my case:

@hourly /root/curl.sh home_network @hourly /root/curl.sh vpn_server

This will execute this script every hour, keeping in track new IPs changes.

Also read: https://man7.org/linux/man-pages/man5/crontab.5.html & https://crontab.guru/

Copyright

Copyright (c) 2022 z3nth10n (VIZZUTA).

License: MIT

#!/bin/bash
# work on directory
mypath=`realpath $0`
dir=`dirname $mypath`
cd `dirname $mypath`
([[ ! -z "$1" ]]) && { echo $1 > instance_id.sh; } || { echo "No specified id param, aborting!"; exit; }
[[ ! -d $1 ]] && mkdir $1
[[ ! -z "$2" && "$2" != "debug" ]] && echo "export NAMECOMUSER=\"$2\"" > $1/user.sh
[[ ! -z "$3" ]] && echo "export NAMECOMTOKEN=\"$3\"" > $1/token.sh
[[ ! -z "$4" ]] && echo "export SERVER=\"$4\"" > $1/server.sh
[[ ! -z "$5" ]] && echo "export HOSTNAME=\"$5\"" > $1/hostname.sh
debug_mode=""
[[ ! -z "$5" || "$2" == "debug" ]] && debug_mode="true"
source $1/user.sh
source $1/token.sh
source $1/server.sh
source $1/hostname.sh
id=$(curl -u "$NAMECOMUSER:$NAMECOMTOKEN" "https://api.name.com/v4/domains/$SERVER/records" | sed -E "s/.+id\"\:([0-9]+).+host.+$HOSTNAME.+/\1/")
ip=$(curl https://api.ipify.org/)
[[ $debug_mode ]] && echo "User: $NAMECOMUSER"
[[ $debug_mode ]] && echo "Token: $NAMECOMTOKEN"
[[ $debug_mode ]] && echo "Server: $SERVER"
[[ $debug_mode ]] && echo "Hostname: $HOSTNAME"
[[ $debug_mode ]] && echo "ID: $id"
[[ $debug_mode ]] && echo "IP: $ip"
echo $(curl -u "$NAMECOMUSER:$NAMECOMTOKEN" "https://api.name.com/v4/domains/$SERVER/records/$id" -X PUT --data "{\"host\":\"$HOSTNAME\",\"type\":\"A\",\"answer\":\"$ip\",\"ttl\":300}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment