RouterOS NOIP域名DDNS更新脚本

已为老胡 2023-11-07 PM 2555℃ 0条

  此脚本的主要功能是更新当前IP、DDNS更新回传信息(单线单拨使用)

  使用方法如下:

  在/System Scheduler下添加一个脚本定时,名称为noip,内容为下面脚本内容,执行时间为10分钟(时间可自定义)


  #定义 no.ip 相关设定,以下自行修改:
  #============================================================
  :local DDNSUser "no-ip帐号"
  :local DDNSPassword "no-ip密码"
  :local DDNSHost "申请的no-ip地址"
  #============================================================
  #以下程式如不了解,建议不要修改:
  #------------------------------------------------------------
  #定义 IP 变量
  :local DDNSIP
  :global DDNSLastIP
  #定义变量默认值
  :if ([ :typeof $DDNSLastIP ] = nil ) do={ $DDNSLastIP "0.0.0.0" }
  #利用HTTP查询Public IP
  /tool fetch address=checkip.dyndns.com src-path=/ mode=http dst-path=("PublicIP");
  :delay 1;
  #读取档案
  :set DDNSIP [/file get PublicIP contents];
  :set DDNSIP [:pick $DDNSIP 0 [:find $DDNSIP ""]];
  :set DDNSIP [:pick $DDNSIP ([:find $DDNSIP ":"]+2) 100];
  #删除档案
  /file remove PublicIP;
  #判断是否要更新 IP
  :if ([ :typeof $DDNSIP ] = nil ) do={
  :log error ("DDNS no.ip: 网络未取得 IP 位址")
  } else={
  :if ($DDNSIP != $DDNSLastIP) do={
  # 更新 DDNS IP
  :local url "/nic/update?hostname=$DDNSHost&myip=$DDNSIP"
  /tool fetch address=dynupdate.no-ip.com src-path=$url mode=http user=$DDNSUser password=$DDNSPassword dst-path=("DDNS_no_ip")
  :delay 1
  # 档案内容
  :local filestr [ /file get "DDNS_no_ip" contents];
  # 删除档案
  :local filename [ /file find name="DDNS_no_ip"];
  /file remove $filename
  # 变更是否成功
  :if ( [ :find $filestr "good"] = "0" || [ :find $filestr "nochg"] = "0" ) do={
  :log warning ("DDNS no.ip: 网络更新 IP 位址 " . $DDNSIP)
  :set DDNSLastIP $DDNSIP
  } else={
  :log error ("DDNS no.ip: 网络更新 IP 位址失败 " . $DDNSIP)
  }
  }
  }


标签: none

非特殊说明,本博所有文章均为博主原创。

评论啦~