Skip to content

Instantly share code, notes, and snippets.

@luginbash
Last active May 2, 2022 03:48
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 luginbash/9da5d15c489460357959 to your computer and use it in GitHub Desktop.
Save luginbash/9da5d15c489460357959 to your computer and use it in GitHub Desktop.
DNS-O-Matic Dynamic IP Endpoint update script for Mikrotik RouterOS
# DNS-O-Matic Dynamic IP Endpoint update script for Mikrotik RouterOS.
#
# Author: Quan Zhou <public_zhou@outlook.com>
#
# Description:
# Update IP address of specified hostname through dnsomatic.com
# You need a dnsomatic.com account and whatsoever ddns service
# supported by them.
#
# Tested ands works with Mikrotik RouterOS 6.32
#
#--------------- Fill out these fields ------------------
#
# Username of your DNS-o-Matic Account. e.g. user@example.org
:local domUsername "<--USERNAME-->";
# DNS-o-Matic Password, not the DDNS service password/api Token
:local domPassword "<--PASSWORD-->";
# Hostname (FQDN)
# e.g. tokyo.example.org. Besides, example.org must be filled in
# DOMAIN field on the DNS-o-Matic control panel.
:local domHostname "<--HOSTNAME-->";
# Which interface should I get IP address from.
# e.g pppoe-out1
:local inetinterface "<--INTERFACE-->";
#--------------------- STOP HERE ------------------------
:global prevBrIP1;
:if ([/interface get $inetinterface value-name=running]) do={
# Get the current IP on the interface
:local currentIP [/ip address get [find interface="$inetinterface" disabled=no] address];
# Strip the net mask off the IP address
:for i from=( [:len $currentIP] - 1) to=0 do={
:if ( [:pick $currentIP $i] = "/") do={
:set currentIP [:pick $currentIP 0 $i];
}
}
:if ($currentIP != $prevBrIP1) do={
:log info "DNS-o-Matic: Updating A record of $domHostname to $currentIP...";
:set prevBrIP1 $currentIP;
:local url "https://updates.dnsomatic.com/nic/update\3Fhostname=$domHostname&myip=$currentIP&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG";
/tool fetch url=$url user=$domUsername password=$domPassword mode=https dst-path=("dnsOmatic-" . $host . ".txt")
:log info "DNS-o-Matic: $domHostname now has A record to $currentIP";
:log info ([/file get ("dnsOmatic-" . $host . ".txt") contents])
} else={
:log info "DNS-o-Matic: nochg $prevBrIP1";
}
} else={
:log info "DNS-o-Matic: $inetinterface is not running, therefore no update will be performed";
}
@Matellito
Copy link

excelent

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