一、首先说明,本篇受“情灭缘尽”转帖的脚本启发,其发布的原始脚本如下:
# Dynamic DNS Update Script v1.1
# ——————————
# This script will perform automatic dynamic dns updates on the Mikrotik
# router platform.  (http://www.mikrotik.com/)  Since Mikrotik does not
# support sending http requests we have created a smtp -> ddns proxy service
# which will take the http URL querystring used for a dynamic dns update and
# process it via email.
# ——————————
# Written by Sam Norris, ChangeIP.com
# 7/31/04 – Created script.
# 12/9/04 – Made some values dynamic (smtp server, dhcp interface)
# ——————————
#
# Instructions:
#    There are a few variables down below that you need to configure for your
#    specific setup.  Please modify the variables in the ‘ddnsInit’ script to
#    reflect your specific information, ie userid, password, hostname to update.
#

# Blow away any existing script code, if necessary.
/system scheduler remove ddnsJob
/system script remove ddnsCheck
/system script remove ddnsInit
/system script remove ddnsReset
/system script remove ddnsSendUpdate

# Setup global variables needed to keep track of changing IP address.
/system script add name="ddnsInit" source={

  :log message="ddnsInit: Creating Dynamic DNS update system."

# ENTER YOUR CHANGEIP.COM USER ID HERE.
  :global u
  :set u "USERID"

# ENTER YOUR CHANGEIP.COM PASSWORD HERE.
  :global p
  :set p "PASSWORD"

  :global s
  :set s "Mikrotik"

# ENTER THE TARGET HOSTNAME TO UPDATE, *1 is Set 1.
  :global h
  :set h "*1"

  :global dhcpInterface
  :set dhcpInterface [ /ip dhcp-client get interface ]
  :log message=("ddnsInit: Found dhcp interface " . $dhcpInterface )

# EMAIL PROXY ADDRESS – DO NOT CHANGE FOR PRODUCTION.
  :global ddnsProxyEmail
  :set ddnsProxyEmail "ddnsUpdate@ChangeIP.com"

# ENTER YOUR EMAIL ADDRESS FOR CONFIRMATIONS.
  :global ddnsFromEmail
  :set ddnsFromEmail "youremail@domain.tld"

# SMTP DDNS PROXY SERVER – CHANGE ONLY IF NECESSARY (port 25 blocked?)
  :global ddnsSmtpServer
  :set ddnsSmtpServer [:resolve smtp.changeip.com]

  :global a
  :set a [ \
    /ip address get \
      [/ip address find interface=$dhcpInterface] \
      address \
    ]

  }

/system script add name="ddnsCheck" source={
  :if ([/system scheduler get ddnsJob run-count]<=1) do={
    /system script run ddnsInit
    }
  :global temp
  :global b
  :set temp $a
  :set b [ \
    /ip address get \
      [/ip address find interface=$dhcpInterface] \
      address \
    ]
  :if ($temp != $b) do={
    :log message="ddnsCheck:  Found new IP address."
    /system script run ddnsSendUpdate
    :set a $b
    }
  }

/system script add name="ddnsSendUpdate" source={
    :log message=("ddnsSendUpdate:  Sending Dynamic DNS smtp update to " . $ddnsSmtpServer)
    /tool e-mail send \
      to=$ddnsProxyEmail \
      from=$ddnsFromEmail \
      server=$ddnsSmtpServer \
      subject="New Dynamic IP" \
      body=("u=" . $u . "&p=" . $p . "&hostname=" . $h . "&system=" . $s . "&myip=" . $b)
  }

/system script add name="ddnsReset" source={

  :log message="ddnsReset:  Resetting global values."
  /system scheduler set ddnsJob run-count=0
  :unset u
  :unset p
  :unset s
  :unset h
  :unset dhcpInterface
  :unset ddnsProxyEmail
  :unset ddnsFromEmail
  :unset ddnsSmtpServer
  :unset a
  :unset b
  :unset temp

  }

/system scheduler add name=ddnsJob interval=30s on-event=ddnsCheck

二、红色部分是需要根据个人注册的信息填写

三、黄色部分是我要着重解释的,也是成功的关键。

四、具体说明:
1、该脚本是基于www.changeip.com网站申请的免费动态域名,大家可自行申请;
2、该脚本的原始作者sam norris就是www.changsip.com的运行者,故此,这个脚本在ros下是绝对支持www.changeip.com申请的域名,至于其他国内的类似www.3322.org等我还没有试过,不知可不可以

3、
  :global dhcpInterface
  :set dhcpInterface [ /ip dhcp-client get interface ]
  :log message=("ddnsInit: Found dhcp interface " . $dhcpInterface )

这是本文的关键部分,sam norris是基于dhcp客户机的架构来设置他的动态域名,而国内用户主要关心的是adsl拨号下得动态域名解析,dhcinterface是一个全局变量,他代表的是dhcp客户机的接口号,也就是分到ip地址的接口设备名,这个变量名可以不改,但如何取得你的系统中adsl设备的接口号呢?请将 [/ip dhcp-client get interface] 改为 [/interface find type=pppoe-out],好了,dhcpinterface的值就变成了你所建立的adsl拨号接口号了,ros内部的表示一般为*3,当然这个不用关心。至此,你所要做的就是等待了;

4、关于脚本的建立我在此就不多说了,大家只要把上述脚本的各个部分复制-粘帖到命令交互界面,自然会生成,正确的结果是生成四个脚本,分别为: ddnsCheck,ddnsInit,ddnsReset,ddnsSendUpdate;同时生成一个名字为ddnsJob的计划日程。

最后祝大家成功,ros自己能做的事情自己做,从此摆脱ros+windows +域名客户软件的日子。

 


本文章由雨豪博客撰写,采用CC授权分享,转载时请注明原文链接。
本文链接: http://www.wx35.cn/archives/148/

随机文章

Comments

Comments are closed.