Skip to content

Instantly share code, notes, and snippets.

@bmiro
Last active June 28, 2021 08:36
Show Gist options
  • Save bmiro/49523ee157b6be1e7c7633a392d64040 to your computer and use it in GitHub Desktop.
Save bmiro/49523ee157b6be1e7c7633a392d64040 to your computer and use it in GitHub Desktop.
# Mikrotik script to update DuckDNS.org domain, to use it:
# - Download it as `duckdns-update`
# - Tune your `duckToken` and `duckDomain` variables
# - Copy it to your router:
# `scp duckdns-update user@you-router:`
# - Add the script
# `/system script add name=duckdns-update source=[ /file get duckdns-update contents ]`
# - Add a periodic task to execute it
# `/system scheduler add name=duckdns-updater interval=1h on-event=duckdns-update`
# - Or execute it manully
# `/system script run duckdns-update`
# Set needed variables
:local duckToken "your-token-uuid"
:local duckDomain "examplesubdomain"
:global previousIP
:log info ("DuckDNS: Check")
/tool fetch mode=http address="whatismyip.akamai.com" host="whatismyip.akamai.com" src-path="/" dst-path=/ip.txt
:local externalIP [/file get ip.txt contents]
:if ($externalIP != $previousIP) do={
:set previousIP $externalIP
/tool fetch mode=https url="https://www.duckdns.org/update?domains=$duckDomain&token=$duckToken&ip=$externalIP" dst-path=duckdns.txt;
:local result [/file get duckdns.txt contents];
:log info "Duck DNS update result: $result";
} else={
:log info ("DuckDNS: IP not changed")
}
@yklim
Copy link

yklim commented Oct 5, 2019

/system script duckdns-update run should be modified like /system script run duckdns-update.
Thank you for sharing a good script.

@bmiro
Copy link
Author

bmiro commented Nov 4, 2019

/system script duckdns-update run should be modified like /system script run duckdns-update.
Thank you for sharing a good script.

Yes! for the advise :D

@Zovereign
Copy link

Thank you. At last I found a working one.!

@beeyev
Copy link

beeyev commented Jun 28, 2021

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