Skip to content

Instantly share code, notes, and snippets.

@oliveratgithub
Created November 5, 2015 14:28
Show Gist options
  • Save oliveratgithub/a50a3d6bcb1e030ed06e to your computer and use it in GitHub Desktop.
Save oliveratgithub/a50a3d6bcb1e030ed06e to your computer and use it in GitHub Desktop.
Automatic Dynamics DNS updater using HTTP API calls, prepared for TwoDNS.de / Two-DNS.de (works with any other DDNS Service, allowing IP updates via HTTP API calls)
#!/bin/sh
log="ddns_updater.log.txt"
my_ext_ip=$(curl -sS http://icanhazip.com)
echo "\n\n\n===== \
\n$(date -u) \
\nUpdating IP to: $my_ext_ip \n" >> $log
curl -isSX PUT \
-u "[email protected]:api_token" \
-H "Content-Type: application/json" \
--data '{"ip_address":"'$my_ext_ip'", "activate_wildcard": "false"}' \
https://api.twodns.de/hosts/host.dynvpn.de >> $log
exit
@gerlof85
Copy link

gerlof85 commented May 14, 2021

the current URL for obtaining external IP doesn't work anymore, the correct one is: http://ipv4.icanhazip.com (or https version)
also expanded the script above to only update to API if current external IP is different from last updated IP, see my gist

@oliveratgithub
Copy link
Author

@gerlof85 cool thanks for pointing this out. It would be possible to make the Shell Script run using nohup and thus won’t need to write the current IP into an additional file - only store it in a global var within the script.

Would this adjustment serve your needs as well?

@gerlof85
Copy link

Your suggestion is indeed very useful, thanks! Currently I have the script scheduled via Cron to fire it up periodically. To run it via nohup there would need to be some sort of loop and a waiting mechanism between the actions. And if I'm understanding it correctly if any changes to the script were to be made, the current nohup instance must be stopped and a new one needs to be started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment