找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 17266|回复: 9

[脚本] 求多线ip自动更新到nat脚本

[复制链接]
发表于 2013-9-29 18:31:25 | 显示全部楼层 |阅读模式
悬赏50铜板已解决
本帖最后由 solaoxo 于 2013-9-29 21:22 编辑

如题,不要是每执行一次ip还没有变化的情况下就更新了to addresses,我自己有一个单线更新的脚本,一线的时候就是ip变化了才更新到to addresses,没变化是不会更新的,用了两个一样的脚本用双线的时候就变成每执行一次更新一次了,感觉这个很不稳定,老是在修改配置了

最佳答案

查看完整内容

:local curaddress :local newaddress :local status :local x :set x 3 :for i from=1 to=$x do={ :set status [/interface get [/interface find name=("pppoe-out" . $i)] running] :if ($status=true) do={ :set newaddress [/ip address get [/ip address find dynamic=yes interface=("pppoe-out" . $i)] address ] :set newaddress [:pick $newaddress 0 [:find $newaddress "/"]] :set curaddress [ ...
routeros
发表于 2013-9-29 18:31:26 | 显示全部楼层
:local curaddress
:local newaddress
:local status
:local x
:set x 3
:for i from=1 to=$x do={
    :set status [/interface get [/interface find  name=("pppoe-out" . $i)] running]
    :if ($status=true) do={
    :set newaddress [/ip address get [/ip address find dynamic=yes interface=("pppoe-out" . $i)] address ]
    :set newaddress [:pick $newaddress 0 [:find $newaddress "/"]]
    :set curaddress [ /ip firewall nat get [/ip firewall nat find comment=("ADSL" . $i)] to-addresses ]
    :if ($curaddress != $newaddress) do={
       /ip firewall nat set [ /ip firewall nat find comment=("ADSL" . $i) ] to-addresses=$newaddress
       :log info ("Change ADSL" . $i . " NAT IP" )
         }
     }
}



这是3线的,自己更改参数。
routeros
回复

使用道具 举报

发表于 2013-9-29 23:14:10 | 显示全部楼层
同求,刚好也遇到这个问题?
routeros
回复

使用道具 举报

发表于 2013-9-29 23:26:01 | 显示全部楼层
没听懂什么意思啊。。有图吗?
routeros
回复

使用道具 举报

发表于 2013-9-30 10:58:51 | 显示全部楼层
:local nyr [/system clock get date]
:local yy ([:find jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec [:pick $nyr 0 3]]+1)
:if ($yy<10) do={:set yy (0 . $yy)}
:set nyr ([:pick $nyr 7 11] . $yy . [:pick $nyr 4 6])
:local curip
:local newip
:local status
:local x1
#设定线路,默认2线
:set x1 3
:for i from=1 to=$x1 do={
    :set status [/interface get [/interface find  name=("pppoe-out" . $i)] running]
    :if ($status=true) do={
    :set newip [/ip address get [/ip address find dynamic=yes interface=("pppoe-out" . $i)] address ]
    :set newip [:pick $newip 0 [:find $newip "/"]]
    :set curip [ /ip firewall nat get [/ip firewall nat find comment=("NAT-" . $i)] to-addresses ]
    :if ($curip != $newip) do={
       /ip firewall nat set [ /ip firewall nat find comment=("NAT-" . $i) ] to-addresses=$newip
:log error ("保存新IP成功")
}
}
}
routeros
回复

使用道具 举报

 楼主| 发表于 2013-9-30 21:20:02 | 显示全部楼层
上面两个脚本原理好像都是一样的,是不是通过对比ip,ip不同才更新的,还是没对比就直接更新过去
routeros
回复

使用道具 举报

发表于 2013-9-30 21:52:38 | 显示全部楼层
是通过对比ip,ip才更新,本人在用
routeros
回复

使用道具 举报

 楼主| 发表于 2013-9-30 22:11:46 | 显示全部楼层
touhgen 发表于 2013-9-30 21:52
是通过对比ip,ip才更新,本人在用

:local nyr [/system clock get date]
:local yy ([:find jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec [:pick $nyr 0 3]]+1)
:if ($yy<10) do={:set yy (0 . $yy)}
:set nyr ([:pick $nyr 7 11] . $yy . [:pick $nyr 4 6])
这段是什么意思的
routeros
回复

使用道具 举报

发表于 2013-9-30 23:02:48 | 显示全部楼层
solaoxo 发表于 2013-9-30 22:11
:local nyr [/system clock get date]
:local yy ([:find jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov ...

###获取当前系统日期
###取当前日期的月份
###检测月份数字少于10
###重设日期数字为双尾数 比如1设置为01

楼上的不知道复制谁的脚本  搞些没用的东西上去
routeros
回复

使用道具 举报

 楼主| 发表于 2013-10-1 04:41:18 | 显示全部楼层
huigezi' 发表于 2013-9-30 23:02
###获取当前系统日期
###取当前日期的月份
###检测月份数字少于10

谢谢了,长知识了
routeros
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|小黑屋|软路由 ( 渝ICP备15001194号-1|渝公网安备 50011602500124号 )

GMT+8, 2024-5-29 15:57 , Processed in 0.059921 second(s), 4 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表