求助~!一个变量连接问题~
本帖最后由 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) 的效果,求高手指点! :global router1 "58.222.227.81"
:global router2 "218.90.213.65"
:put [$router1 . $router2] 本帖最后由 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))这个变量不工作 没见过这种写法。只能通过别的方式获取到这个变量,而不是把字符组合成变量名去获取。 :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} :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}
} 注意ROS版本不同,脚本编写也不同。 {
:local test {}
:set test (11.11.11.11,22.22.22.22)
:put [:pick $test 0]
:put [:pick $test 1]
}
楼主你为何不用这样的变量定义方式呢 哈哈 楼上正解,谢谢各位的帮忙! :global a1 aaa
:global a2 bbb
:foreach i in=($a1,$a2) do={/put $i } yus 发表于 2012-3-26 18:29 static/image/common/back.gif
:global a1 aaa
:global a2 bbb
:foreach i in=($a1,$a2) do={/put $i }
快来看啊,余老师来了!围观啊:lol
页:
[1]