Skip to content

Instantly share code, notes, and snippets.

@marcoleong
Created July 4, 2015 14:28
Show Gist options
  • Save marcoleong/2c96b7418e519be5fd90 to your computer and use it in GitHub Desktop.
Save marcoleong/2c96b7418e519be5fd90 to your computer and use it in GitHub Desktop.
Mitrotik Router Dynamic DNS update script for Namecheap DDNS
:log info "NamecheapDDNS: start updating..."
:global ddnspass "yourownddnspass"
:global theinterface "pppoe-out1"
:global ddnshost "subdomain"
:global ddnsdomain "example.com"
:global ipddns [:resolve "$ddnshost.$ddnsdomain"];
:global ipfresh [ /ip address get [/ip address find interface=$theinterface ] address ]
:if ([ :typeof $ipfresh ] = nil ) do={
:log info ("NamecheapDDNS: No ip address on $theinterface .")
} else={
:for i from=( [:len $ipfresh] - 1) to=0 do={
:if ( [:pick $ipfresh $i] = "/") do={
:set ipfresh [:pick $ipfresh 0 $i];
}
}
:if ($ipddns != $ipfresh) do={
:log info ("NamecheapDDNS: IP-NamecheapDDNS = $ipddns")
:log info ("NamecheapDDNS: IP-Fresh = $ipfresh")
:log info "NamecheapDDNS: Update IP needed, Sending UPDATE...!"
:global str "/update?host=$ddnshost&domain=$ddnsdomain&ip=$ipfresh&password=$ddnspass"
/tool fetch address=dynamicdns.park-your-domain.com src-path=$str mode=https
:delay 1
:global str [/file find name="NamecheapDDNS.$ddnshost.$ddnsdomain"];
/file remove $str
:global ipddns $ipfresh
:log info "NamecheapDDNS: IP updated to $ipfresh!"
} else={
:log info "NamecheapDDNS: dont need changes";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment