Last active
December 22, 2021 22:52
-
-
Save pbrooko/beeca4bbf9e9e5033f9e28da2f0db0ce to your computer and use it in GitHub Desktop.
RouterOS (v5+) script to update Hurricane Electric Dynamic DNS address
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Update Hurricane Electric DDNS IPv4 address | |
# This script will work on RouterOS v5+ | |
# Customize the following variables: | |
:local ddnshost "<DDNS HOST NAME>" | |
:local key "<PASSWORD>" | |
:local WANinterface "<INTERFACE>" | |
:local updatehost "dyn.dns.he.net" | |
:local outputfile ("HE_DDNS" . ".txt") | |
# Internal processing below... No more changes required! | |
# ------------------------------------------------------ | |
:if ([/interface get $WANinterface value-name=running]) do={ | |
:local ipv4addr | |
# Get WAN interface IP address | |
:set ipv4addr [/ip address get [/ip address find interface=$WANinterface] address]; | |
:set ipv4addr [:pick [:tostr $ipv4addr] 0 [:find [:tostr $ipv4addr] "/"]]; | |
:if ([:len $ipv4addr] = 0) do={ | |
:log error "HE-DDNS: Could not get IP for interface $WANinterface"; | |
:error "HE-DDNS: Could not get IP for interface $WANinterface"; | |
} | |
:local previousIP [:resolve "$ddnshost"]; | |
:log info "HE-DDNS: Previous IP: $previousIP, interface IP: $ipv4addr"; | |
:if ($ipv4addr != $previousIP) do={ | |
:log info "HE-DDNS: Current IP $ipv4addr is not equal to previous IP $previousIP, update needed"; | |
:log info "HE-DDNS: Sending update for $ddnshost"; | |
# Do the update | |
/tool fetch mode=https url="https://$ddnshost:$key@$updatehost/nic/update?hostname=$ddnshost&myip=$ipv4addr" dst-path=$outputfile; | |
:log info [/file get ($outputfile) contents]; | |
:log info "HE-DDNS: Host $ddnshost updated on HE-DDNS with IP $ipv4addr"; | |
/file remove $outputfile; | |
} else={ | |
:log info "HE-DDNS: Previous IP $previousIP is equal to current IP, no update needed"; | |
} | |
} else={ | |
:log info "HE-DDNS: $WANinterface is not currently running, so therefore will not update."; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment