mikrotik ¿¡¼­ dyndns ÀÚµ¿ IP ¾÷µ¥ÀÌÆ® ver 2

Leo   
   Á¶È¸ 7094   Ãßõ 0    

아래 dyndns 자동 업데이트 스크립트를 살짝 바꿔서
dyndns 에 2개의 hostname 을 등록했을때 2개 모두 업데이트 하도록 하는 스크립트를 만들어 봤습니다.

:local username "<dyndns id>";
:local password "<dyndns password>";
:local hostname { "first"="<dyndns hostname1>"; "second"="<dyndns hostname2>" }
:local inetinterface "ether1-gateway";
:local sysdate [/system clock get date];
:local systime [/system clock get time];
:local sysname [/system identity get name];

:local dyndnsForce;
:set dyndnsForce false;

# Print debug info
#:log info ("DynDNS: username = $username");
#:log info ("DynDNS: password = $password");
#:log info ("DynDNS: hostname1 = $hostname->first");
#:log info ("DynDNS: hostname2 = $hostname->second");

# Check if WAN interface is running
:if ([/interface get $inetinterface value-name=running]) do={

# Get the current IP on the WAN interface
    :local currentIP [/ip address get [find interface="$inetinterface" disabled=no] address];

# Strip the net mask off the IP address
    :set currentIP [:pick $currentIP 0 [:find $currentIP "/"]];
    :log info ("DynDNS: current WAN IP = $currentIP");

# do loop for all hostname
    :foreach key,value in=$hostname do={

# Get resolved IP for hostname
        :local resolvedIP [:resolve domain-name=$value server=8.8.8.8];
        :log info ("DynDNS: resolved IP for $value = $resolvedIP");

# Determine if dyndns update is needed
        :if (($currentIP != $resolvedIP) || ($dyndnsForce = true)) do={
            :set dyndnsForce false;
            /tool fetch user=$username password=$password url="http://members.dyndns.org/nic/update\?hostname=$value&myip=$currentIP&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG" dst-path="/dyndns.txt";
            :delay 1;
            :local result [/file get dyndns.txt contents]
            :log info ("DynDNS: update needed for $value")
            :log info ("DynDNS: update result for $value = ".$result)
        } else={
            :log info ("DynDNS: no update needed for $value");
        }

# end of loop for all hostname
    }

# if WAN interface is not running
} else={
    :log info ("DynDNS: $inetinterface is not currently running");
}

mikrotik 으로 스크립트 프로그램 짜는 것도 은근 재밌군요. :)


Á¦¸ñPage 51/104
05-20   6989   ´Ð³×ÀÓ
2020-04   7002   Çã´çs
2020-05   7023   »õ·Î¿îÂ÷¿ø
2015-12   7034   MikroTikÀÌÁø
2019-11   7042   ¾Æ¸Â´Ù³»¿ì»ê
2018-06   7044   ÃÊ»ý´Þ
2022-08   7051   °í·¡1006
2015-06   7053   NightHawk
2019-04   7068   ±èȲÁß
2017-03   7073   ÀÌÅ¿í
2015-11   7085   º¸°Å½º123
2014-03   7095   Leo
2020-10   7098   ¼ÛÁÖȯ
2020-06   7102   Elsaphaba
2016-08   7107   ±è±â·æ
2020-05   7111   Elsaphaba
2019-06   7112   Æä¼±»ý
2016-01   7113   jbmex
2019-10   7120   ±×¸®Æù0
2015-07   7122   ȲÀ籤