找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 4649|回复: 10

[脚本] 求助~!一个变量连接问题~

[复制链接]
发表于 2012-3-24 10:11:45 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

×
本帖最后由 rdfp 于 2012-3-24 12:04 编辑

:global router1 "222.222.227.81"
:global router2 "218.218.213.65"
:for i from 1 to 2 do={:put ($("router" . $i))}

我想达到分别 put ($router1) 和 put ($router2) 的效果,求高手指点!
routeros
发表于 2012-3-24 11:47:49 | 显示全部楼层
:global router1 "58.222.227.81"
:global router2 "218.90.213.65"
:put [$router1 . $router2]
routeros
回复

使用道具 举报

 楼主| 发表于 2012-3-24 11:54:03 | 显示全部楼层
本帖最后由 rdfp 于 2012-3-24 12:05 编辑

:global wannum "2"
:global router1 "222.222.227.81"
:global router2 "218.218.213.65"
:global wanface "wan"
:global lanip "192.168.1.0/24"
:for i from 1 to $wannum do={/ip firewall mangle add action=mark-connection chain=prerouting comment=("pcc-". $i) connection-state=new disabled=no new-connection-mark=($i) passthrough=yes per-connection-classifier=("both-addresses:" . ($wannum . "/" . ($i - 1))) src-address=($lanip)}
:for i from 1 to $wannum do={/ip firewall mangle add action=mark-routing chain=prerouting comment=("route-" . $i) connection-mark=($i) disabled=no new-routing-mark=($i) passthrough=no src-address=($lanip)}
:for i from 1 to $wannum do={/ip firewall nat add action=masquerade chain=srcnat comment=("nat-" . $i) connection-mark=($i) disabled=no out-interface=($wanface . $i) src-address=($lanip)}
/ip firewall nat add action=masquerade chain=srcnat comment="default" disabled=no src-address=($lanip)


:for i from 1 to $wannum do={/ip route add comment=($i) disabled=no dst-address=0.0.0.0/0 gateway=($("router" . $i)) routing-mark=($i) scope=30 target-scope=10}


我就是想把$i 在最后一行里面弄起来 要不然要重复修改,但是=($("router" . $i))  这个变量不工作
routeros
回复

使用道具 举报

发表于 2012-3-24 12:22:29 | 显示全部楼层
没见过这种写法。只能通过别的方式获取到这个变量,而不是把字符组合成变量名去获取。
routeros
回复

使用道具 举报

发表于 2012-3-25 04:21:20 | 显示全部楼层
:local a1 "3.3.3.3"
:local a2 "4.4.4.4"
:for i from=1 to=2 do={
if (i=1) do={:put $a1}
if (i=2) do={:put $a2}
routeros
回复

使用道具 举报

发表于 2012-3-25 04:24:54 | 显示全部楼层
:for i from 1 to $wannum do={
if (i=1) do={
/ip route add comment=($i) disabled=no dst-address=0.0.0.0/0 gateway=($router1) routing-mark=($i) scope=30 target-scope=10}
if (i=2) do={/ip route add comment=($i) disabled=no dst-address=0.0.0.0/0 gateway=($router2) routing-mark=($i) scope=30 target-scope=10}
}
routeros
回复

使用道具 举报

发表于 2012-3-25 04:35:11 | 显示全部楼层
注意ROS版本不同,脚本编写也不同。
routeros
回复

使用道具 举报

发表于 2012-3-25 05:24:00 | 显示全部楼层
{
:local test {}
:set test (11.11.11.11,22.22.22.22)
:put [:pick $test 0]
:put [:pick $test 1]
}

楼主你为何不用这样的变量定义方式呢
routeros
回复

使用道具 举报

 楼主| 发表于 2012-3-26 17:07:35 | 显示全部楼层
哈哈 楼上正解,谢谢各位的帮忙!
routeros
回复

使用道具 举报

发表于 2012-3-26 18:29:21 | 显示全部楼层
:global a1 aaa
:global a2 bbb
:foreach i in=($a1,$a2) do={/put $i }
routeros
回复

使用道具 举报

发表于 2012-3-26 19:04:35 | 显示全部楼层
routeros
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-6-2 07:42 , Processed in 0.067342 second(s), 9 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2023 Discuz! Team.

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