找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 9125|回复: 2

[脚本] 寻找默认网关接口IP

[复制链接]
发表于 2013-11-18 22:50:15 | 显示全部楼层 |阅读模式

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

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

×
ros版本5.22,用了网上搜的脚本
                         :global adgw [/ip route get [/ip route find static=yes active=yes dynamic=yes distance=1] gateway]
                                        :global ip [/ip add get [find network=$adgw] address]
                                        :global newip [:pick $ip 0 [:find $ip "/"]]
             提示错误,没有这个变量,如图,请高手请教.
1.jpg
routeros
 楼主| 发表于 2013-11-19 09:44:23 | 显示全部楼层
换个角度问问题,谁能把以下脚本优化下,如果用以下脚本,线路多的情况下,写起来太麻烦了,


:local status [/interface pppoe-client get [/interface pppoe-client find name="pppoe-out1"] running];
:if ($status=true) do={
:set ether "pppoe-out1"};
:if ($status=false) do={
:local status [/interface pppoe-client get [/interface pppoe-client find name="pppoe-out2"] running];
:if ($status=true) do={
:set ether "pppoe-out2"};
:if ($status=false) do={
:local status [/interface pppoe-client get [/interface pppoe-client find name="pppoe-out3"] running];
:if ($status=true) do={
:set ether "pppoe-out3"};
:if ($status=false) do={
:local status [/interface pppoe-client get [/interface pppoe-client find name="pppoe-out4"] running];
:if ($status=true) do={
:set ether "pppoe-out4"};
:if ($status=false) do={
:local status [/interface pppoe-client get [/interface pppoe-client find name="pppoe-out5"] running];
:if ($status=true) do={
:set ether "pppoe-out5"};
:if ($status=false) do={
:local status [/interface pppoe-client get [/interface pppoe-client find name="pppoe-out6"] running];
:if ($status=true) do={
:set ether "pppoe-out6"};
:if ($status=false) do={
:local status [/interface pppoe-client get [/interface pppoe-client find name="pppoe-out7"] running];
:if ($status=true) do={
:set ether "pppoe-out7"};
:if ($status=false) do={
:local status [/interface pppoe-client get [/interface pppoe-client find name="pppoe-out8"] running];
:if ($status=true) do={
:set ether "pppoe-out8"};
:if ($status=false) do={
:local status [/interface pppoe-client get [/interface pppoe-client find name="pppoe-out9"] running];
:if ($status=true) do={
:set ether "pppoe-out9"};
:if ($status=false) do={
:local status [/interface pppoe-client get [/interface pppoe-client find name="pppoe-out10"] running];
:if ($status=true) do={
:set ether "pppoe-out10"};
:if ($status=false) do={
:local status [/interface pppoe-client get [/interface pppoe-client find name="pppoe-out11"] running];
:if ($status=true) do={
:set ether "pppoe-out11"};
:if ($status=false) do={
:local status [/interface pppoe-client get [/interface pppoe-client find name="pppoe-out12"] running];
:if ($status=true) do={
:set ether "pppoe-out12"};
:if ($status=false) do={
:local status [/interface pppoe-client get [/interface pppoe-client find name="pppoe-out13"] running];
:if ($status=true) do={
:set ether "pppoe-out13"};
:if ($status=false) do={
:local status [/interface pppoe-client get [/interface pppoe-client find name="pppoe-out14"] running];
:if ($status=true) do={
:set ether "pppoe-out14"};
:if ($status=false) do={
:local status [/interface pppoe-client get [/interface pppoe-client find name="pppoe-out15"] running];
:if ($status=true) do={
:set ether "pppoe-out15"};
:if ($status=false) do={
:set ether "pppoe-out1"}}}}}}}}}}}}}}}


我的思路是,既然不能提取默认网关的IP,那么就取其它已连接出口的IP,
routeros
回复

使用道具 举报

发表于 2013-11-22 13:49:40 | 显示全部楼层
试下这个
:local newip [ /ip route get [/ip route find active=yes dynamic=yes connect=yes gateway=("pppoe-out" . "$i")] pref-src ]
routeros
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-11-21 21:20 , Processed in 0.088593 second(s), 5 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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