# DNSEver update script v1.1 # http://www.mizniz.net/9 :local userId "myUserId"; :local authCode "myAuthCode"; :local hosts "mydomain1.com,mydomain2.com"; :local gatewayInterface "ether1-gateway"; :local secureUpdate no; :local saveResult yes; :global previousIpAddress; :if ([/interface find where name=$gatewayInterface running=yes] != "") do={ # Get the current IP on the interface :local currentIpAddress [/ip address get [find interface="$gatewayInterface" disabled=no] address]; # Strip the net mask off the IP address :for i from=( [:len $currentIpAddress] - 1) to=0 do={ :if ( [:pick $currentIpAddress $i] = "/") do={ :set currentIpAddress [:pick $currentIpAddress 0 $i]; } } :if ($currentIpAddress != $previousIpAddress) do={ :log info "ddns: Current ip address ($currentIpAddress) is not equal to previous ip address, update needed"; :set previousIpAddress $currentIpAddress; :local urlScheme "http"; :if ($secureUpdate) do={ :set urlScheme "https"; } :local hostQueryString ""; :foreach host in=[:toarray $hosts] do={ :if ([:len $hostQueryString] > 0) do={ :set hostQueryString ($hostQueryString . "&"); } # %5B is percent encoded hex for '['. %5D is percent encoded hex for ']'. :set hostQueryString ($hostQueryString . "host%5B$host%5D=$currentIpAddress"); } # The update URL. Note the "\3F" is hex for question mark (?). Required since ? is a special character in commands. /tool fetch url="$urlScheme://dyna.dnsever.com/update.php\3F$hostQueryString" user=$userId password=$authCode keep-result=$saveResult; :log info "ddns: Hosts updated on DNSEver with ip address ($currentIpAddress)."; } } else={ :log error "ddns: Interface ($gatewayInterface) is invalid or not currently running."; }