Created
July 4, 2015 14:28
-
-
Save marcoleong/2c96b7418e519be5fd90 to your computer and use it in GitHub Desktop.
Mitrotik Router Dynamic DNS update script for Namecheap DDNS
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
: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