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

Leo   
   Á¶È¸ 7250   Ãßõ 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 104/105
2016-08   25367   »õÃÑ
2016-02   25388   ÀÌÁ¾¼Û1
2023-09   25524   °í¼¼»ï
2014-02   25674   MikroTikÀÌÁø
2023-09   25892   µ¥Ä«¿À½º
2016-02   25931   öÀÌ´Ô
2015-02   26059   ²Ù±¸±Ã
2023-03   26313   °í¾çÀ̴¾ֿË
2014-08   26442   ȸ¿øK
2015-04   26495   Jjun
2021-01   26522   È÷Áö
2016-09   26579   ³ª³ëÅ¥ºê
2016-03   26621   ¿¡½ºÆijÄ
2023-03   26646   ³¥³¥¸Ç
2014-07   26651   ȸ¿øK
2015-03   26719   Àç·ÕŸÀÓ
2023-03   26937   CandleNo1
2023-06   27279   ³­³ª¾ß1424
2020-06   28110   ¶±»§
2014-05   28113   ´«ºû¸¶À½