Mikrotik RouterOS脚本_更新Hurricane Electric的tunnelbroker DDNS

# update_20230828
# update Hurricane Electric ddns

:local slog "::The Start -- Update Hurricane Electric DDNS..."
:local elog "::The End -- Update Hurricane Electric DDNS..."

:log info ("  ------" . "\n" . $slog)

:local HEusrhost "www.your.domain";
:local HEddnskey "www.tunnelbroker.net_adanced_he-Dynamic-DNS-Settings_API-Key";
:local HEhost "dyn.dns.he.net";
:local HEpath "/nic/update";
:local WANether "pppoe-out1";
:local HEotptfile ("external/" . "HE_DDNS" . ".txt");

:local lwanaddr4;\
:set lwanaddr4 [/ip address get [/ip address find \
  interface=$WANether] address];
:set lwanaddr4 [:pick [:tostr $lwanaddr4] 0 \
  [:find [:tostr $lwanaddr4] "/"]];

:if ([:len $lwanaddr4] = 0) do={
   :log error (" :Could not get IP for interface " . \
     $WANether  . "\n" . $elog  . "\n"  . "    - - - - - -");
   :error  message=(" :Could not get IP for interface " . \
     $WANether . "\n::The End -- Update Hurricane Electric DDNS...");
};

:local lHE4now;
:do {
  /ip dns cache flush;\
  :set lHE4now [:resolve "$HEusrhost"];
    } on-error={\
      :log warning (" :failed to resolve " . $HEusrhost . \
        ". Will updating HE-DDNS Client IPv4 address" . \
        "to new IP: " . $lwanaddr4 . "directly...");

        /tool fetch mode=http url=(\
        "https://" . $HEhost . \
        $HEpath . "?hostname=" . \
        $HEusrhost . "&password=" . \
        $HEddnskey . "&myip=" . \
        $lwanaddr4) dst-path=($HEotptfile);

        :log info (" :" . [/file get ($HEotptfile) contents] . \
          "\n" . $elog  . "\n"  . "    - - - - - -");
        :error  message=" :Failed to resolve, Updated directly.";
      };

:log info (" :RecordDNS is " . $lHE4now . "; MyWanIP is " . \
  $lwanaddr4 . ".");

:if ($lHE4now = $lwanaddr4) do={\
      :log info (" :HEDNS nochg" . "\n" . $elog  . "\n"  . \
        "    - - - - - -");
        } else={\
      :log info (":Updating HE DDNS Client IPv4 addr" . \
        "to new IP: " . $lwanaddr4 . "...");\

        /tool fetch mode=http url=(\
          "https://" . \
            $HEhost . $HEpath . \
            "?hostname=" . $HEusrhost . \
              "&password=" . $HEddnskey . \
                "&myip=" . $lwanaddr4\
                  ) \
                    dst-path=($HEotptfile);

                      :log info (" :" . [/file get ($HEotptfile) contents] . \
                        "\n" . $elog  . "\n"  . "    - - - - - -");
        };
/
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值