码迷,mamicode.com
首页 > 其他好文 > 详细

ROS的DDNS脚本

时间:2015-05-05 23:21:36      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:

ROS使用ADSL上网时,每次拨号IP都会改变,导致外网访问ROS服务器失败,目前最常见的解决方案是使用DDNS这种动态域名工具,在拨号后(IP发生变化后)通知DDNS服务器更新IP,最终使用DDNS服务商提供的静态域名即可永久访问这台服务器。ROS官方仅支持changeip,但通过其它方法也可以实现支持花生壳,测试通过的脚本如下:

一、国外changeip的脚本,修改自changeip官方网站:

 1 # Define User Variables
 2 :global ddnsuser "user"
 3 :global ddnspass "password"
 4 :global ddnshost "xxxx.onmypc.org"
 5 :global ddnsinterface "changkuan"
 6 
 7 # Define Global Variables
 8 :global ddnsip
 9 :global ddnslastip
10 
11 :if ([ :typeof $ddnslastip ] = nothing ) do={ :global ddnslastip "0" }
12 
13 # Grab the current IP address on that interface.
14 :global ddnsip [ /ip address get [/ip address find interface=$ddnsinterface ] address ]
15 :log info $ddnsip
16 # Did we get an IP address to compare?
17 :if ([ :typeof $ddnsip ] = nil ) do={
18    :log info ("DDNS: No ip address present on " . $ddnsinterface . ", please check.")
19 } else={
20 
21   :if ($ddnsip != $ddnslastip) do={
22 
23     :log info "DDNS: Sending UPDATE!"
24     :log info [ :put [/tool dns-update name=$ddnshost address=[:pick $ddnsip 0 [:find $ddnsip "/"] ] key-name=$ddnsuser key=$ddnspass ] ]
25     :global ddnslastip $ddnsip
26 
27   } else={ 
28     :log info "DDNS: No update required."
29   }
30 
31 }
32 
33 # End of script

二、国内花生壳的脚本,官方提供的脚本每次都会更新,根据上述changip脚本修改之,实现IP变化后才更新:

 1 local server "http://ddns.oray.com"
 2 local domain "xxxx.oicp.net"
 3 local users "user"
 4 local paswd "password"
 5 local adslinterface "changkuan"
 6 local ipaddr
 7 :global lastipaddr
 8 
 9 set ipaddr [/ip address get [/ip address find interface=$adslinterface] address]
10 :if ([ :typeof $ipaddr ] = nil ) do={
11    :log info ("ORAY: No ip address present on " . $adslinterface . ", please check.")
12 } else={
13    set ipaddr [:pick $ipaddr 0 ([len $ipaddr] -3)]   
14    :log info $ipaddr
15    :if ($ipaddr != $lastipaddr) do={
16     local par "/ph/update?&hostname=$domain&myip=$ipaddr"
17     :log info "ORAY: Sending UPDATE!"
18     :log info [:put [ /tool fetch url=($server . $par) mode=http user=$users password=$paswd ] ]
19     :global lastipaddr $ipaddr
20 
21   } else={ 
22     :log info "ORAY: No update required."
23   }
24 }

 

ROS的DDNS脚本

标签:

原文地址:http://www.cnblogs.com/lxwy/p/4480514.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!