Skip to content

Instantly share code, notes, and snippets.

@MuhaddiMu
Created October 21, 2020 15:28
Show Gist options
  • Save MuhaddiMu/d640e2e7a5b6b6b19af3f1196e1f649c to your computer and use it in GitHub Desktop.
Save MuhaddiMu/d640e2e7a5b6b6b19af3f1196e1f649c to your computer and use it in GitHub Desktop.
[QUICK] Auto Update DNS-O-Matic & Open DNS IP in macOS/Linux
#!/bin/bash
STATUS="Offline"
REQ_STATUS="Online"
#Check if connected to the internet
nc -z 8.8.8.8 53 >/dev/null 2>&1
online=$?
if [ $online -eq 0 ]; then
STATUS="Online"
else
STATUS="Offline"
fi
if [ "$STATUS" = "$REQ_STATUS" ]; then
IP="$(/usr/bin/dig myip.opendns.com +short)"
echo ${IP}
REQUEST="$(curl --request POST --url https://Muhaddisshah%40gmail.com:gD%[email protected]/nic/update?hostname=all.dnsomatic.com&myip={$IP}&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG)"
echo ${REQUEST}
else
echo "Your internet status is " ${STATUS}
fi
# You can set up automator in macOS and cron job in Linux environment to update the IP address every X minutes
# Note that this will update all services registered with DNS-O-Matic to the new IP address
# DNS-O-Matic API docs: https://www.dnsomatic.com/docs/api
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment