动态域名更新的实现方法 -- 我的Script
我是参考这个帖子做的:http://bbs.routerclub.com/thread-9371-1-1.html
原贴在我机子上有点问题,改成如下,可正常使用,欢迎大家交流!
adscrz@163.com
附录Scrip:
# 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 "adscrz"
# ENTER YOUR CHANGEIP.COM PASSWORD HERE.
:global p
:set p "××××××××"
:global s
:set s "Mikrotik"
# ENTER THE TARGET HOSTNAME TO UPDATE, *1 is Set 1.
:global h
:set h "*1"
:global dhcpInterface
:log message=("Get interface" )
:set dhcpInterface "pppoe-out1"
: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"
:set ddnsFromEmail "adscrz@163.com"
# 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 \
\
address \
]
}
/system script add name="ddnsCheck" source={
#开机后运行几次
:if ( < 120s ) do={
:log message=("Start time =" . )
:log message=("Will run ddnsSendUpdate...")
/system script run ddnsSendUpdate
}
:if (<=1) do={
/system script run ddnsInit
}
:global temp
:global b
:set temp $a
:set b [ \
/ip address get \
\
address \
]
:log message=("IP address: " . $b )
: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
/system scheduler add name=ddnsupdate interval=60m on-event=ddnsSendUpdate 晕死,你用的是什么版本的ROS啊? 有这以复杂吗?我好像没超过100个字母就给搞定了 是2.8版的ROS吧 原帖由 专卖精品 于 2007-3-6 11:32 发表
晕死,你用的是什么版本的ROS啊?
有简单的吗~~能说说吗???
回复 #3 网络-浪子 的帖子
>有这以复杂吗?我好像没超过100个字母就给搞定了咋不分享一下你的成果呢?
谢谢 真的是复杂了.50个字就够了..
:global ddns-user "帐号"
:global ddns-pass "密码"
:global ddns-host "域名"
:global ddns-interface [ /interface find type=pppoe-out ]
:global ddns-ip [ /ip address get address ]
:global ddns-lastip [:resolve 域名]
:if ([:pick $ddns-ip 0 [:find $ddns-ip "/"] ] != $ddns-lastip) do={
/tool dns-update name=$ddns-host address=[:pick $ddns-ip 0 [:find $ddns-ip "/"] ] key-name=$ddns-user key=$ddns-pass
}
放到计划任务里,几分钟执行一次就OK..
[ 本帖最后由 casper2000 于 2007-3-9 17:48 编辑 ]
回复 #7 casper2000 的帖子
佩服佩服!!!这里的高手真不少啊 原帖由 casper2000 于 2007-3-9 17:42 发表 http://bbs.routerclub.com/images/common/back.gif
真的是复杂了.50个字就够了..
:global ddns-user "帐号"
:global ddns-pass "密码"
:global ddns-host "域名"
:global ddns-interface [ /interface find type=pppoe-out ]
:global ddns-ip [ /ip addre ...
假设我的帐号是dg123、密码是123456、域名是dg123.dns1.us 按你的脚本修改后如下:
:global ddns-user "dg123"
:global ddns-pass "123456":global ddns-host "dg123.dns1.us"
:global ddns-interface [ /interface find type=pppoe-out ]
:global ddns-ip [ /ip address get address ]
:global ddns-lastip [:resolve dg123.dns1.us]
:if ([:pick $ddns-ip 0 [:find $ddns-ip "/"] ] != $ddns-lastip) do={
/tool dns-update name=$ddns-host address=[:pick $ddns-ip 0 [:find $ddns-ip "/"] ] key-name=$ddns-user key=$ddns-pass
}
但每次都是提示:Authentication Failure
请问是什么原因呢?!ip-DNS里已设置成当地的DNS 202.96.128.86,202.96.128.166
[ 本帖最后由 dghj_aaron 于 2007-5-6 20:09 编辑 ] 怎么没有人能帮我分析一下问题啊!?回贴的人越来越少了,再次请求高手出手解救!! 已解决~~设置DNS 东莞为202.96.128.86,202.96.128.166,成功更新DDNS
:log info "DDNS:Begin"
:global ddns-user "dg123"
:global ddns-pass "123456"
:global ddns-host "dg123.dns1.us"
:global ddns-ip [ /ip address get address ]
:if ([ :typeof $ddns-lastip ] = nil ) do={ :global ddns-lastip 0.0.0.0/0 }
:if ([ :typeof $ddns-ip ] = nil ) do={
:log info ("DDNS: No ip address present on " . $ddns-interface . ", please check.")
} else={
:if ($ddns-ip != $ddns-lastip) do={
:log info "DDNS: Sending UPDATE!"
:log info [ /tool dns-update name=$ddns-host address=[:pick $ddns-ip 0 [:find $ddns-ip "/"] ] key-name=$ddns-user key=$ddns-pass ]
:global ddns-lastip $ddns-ip
} else={
:log info "DDNS: Not Change"
}
}
:log info "DDNS: DDNS End" 但不知道为什么到网站查IP是正确的,但是ping dg123.dns1.us 却始终是错误的IP。能有人解答一下吗?! 怎么都是我自问自答啊!问得太简单了吗?
页:
[1]