Mikrotik RouterOS용 DynDNS DDNS 업데이트 스크립트

DynDNS 업데이트 스크립트 v1.1입니다. https를 사용하여 업데이트 할 수 있게 수정했고 업데이트 결과를 저장 할 것인지 선택 할 수 있습니다.

userIdDynDNS 아이디
passwordDynDNS 비밀번호
hosts업데이트할 호스트. 여러개일 때 콤마로 구분합니다. 빈 공백은 넣지 마세요.
gatewayInterface공인 아이피를 받는 인터페이스입니다. 보통 ether1-gateway이므로 그대로 두면됩니다.
secureUpdateyes면 https를 사용하여 업데이트 하고 no면 http를 사용합니다. https는 RouterOS v6에서부터 지원됩니다.
saveResultyes면 업데이트 결과를 저장합니다. no는 저장하지 않습니다.

수정하시고 스케줄러에 몇분 간격으로 실행되게끔 넣어주면 됩니다.

ddns-dyndns.txt

# DynDNS update script v1.1
# http://www.mizniz.net/14

:local userId "myId";
:local password "myPassword";
:local hosts "mydomain1.com,mydomain2.com";
:local gatewayInterface "ether1-gateway";
:local secureUpdate yes;
: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";
		}
		
# The update URL. Note the "\3F" is hex for question mark (?). Required since ? is a special character in commands.
        /tool fetch url="$urlScheme://members.dyndns.org/nic/update\3Fhostname=$hosts&myip=$currentIpAddress" user=$userId password=$password keep-result=$saveResult;
        :log info "ddns: Hosts updated on DynDNS with ip address ($currentIpAddress).";
    }
} else={
    :log error "ddns: Interface ($gatewayInterface) is invalid or not currently running.";
}