找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 9255|回复: 5

[脚本] ros自动arp绑定,并使用arp表初始化dhcp表

[复制链接]
发表于 2016-5-6 23:33:09 | 显示全部楼层 |阅读模式

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

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

×
ros自动arp绑定,并使用arp表初始化dhcp表
:foreach wbsz in=[/ip arp find dynamic=yes ] do=[/ip arp add copy-from=$wbsz]
:foreach wxy in [/ip dhcp-server lease find] do={/ip dhcp-server lease remove $wxy}
:foreach wbsz in=[/ip arp find dynamic=no ] do={/ip dhcp-server lease add address=[/ip arp get $wbsz address] mac-address=[/ip arp get $wbsz mac-address]}
routeros
发表于 2016-5-7 13:53:20 | 显示全部楼层
本帖最后由 cspm333 于 2016-5-7 17:32 编辑

小弟試著編繹,發現樓主最大的邏輯問題是把/ip dhcp-server lease dynamic轉成static,
下次循環時,因foreach wxy in [/ip dhcp-server lease find] do={/ip dhcp-server lease remove $wxy}的關係,
又將/ip dhcp-server lease清空了...這不斷線才怪!!

script除轉換外,/ip dhcp-server lease static保留 與不保留應該要做取捨才對.

小弟的編繹:
:foreach dhcps in=[/ip dhcp-server lease find] \
    do={
           :local mac
           :if ([/ip dhcp-server lease get $dhcps dynamic]) \
               do={:set mac [/ip dhcp-server lease get $dhcps active-mac-address]} \
               else={:set mac [/ip dhcp-server lease get $dhcps mac-address]}

           :if ([:len [/ip arp find mac-address=$mac]]=0) \
               do={/ip dhcp-server lease remove $dhcps} \
               else={
                        :local arp [/ip arp find mac-address=$mac]
                        :if ([/ip dhcp-server lease get $dhcps dynamic]) \
                            do={/ip dhcp-server lease make-static $dhcps} \
                            else={:if ([/ip dhcp-server lease get $dhcps address]!=[/ip arp get $arp address]) \
                                          do={/ip dhcp-server lease set $dhcps address=[/ip arp get $arp address]}}
                        :if ([/ip arp get $arp dynamic]) do={/ip arp add copy-from=$arp}
                       }
          }
routeros
回复 1 0

使用道具 举报

发表于 2016-5-7 02:28:34 | 显示全部楼层
這是您編繹的script嗎? 有小缺失喔
如:arp裡的並不只來自Lan的dhcp-clients ,非pppoe用戶也會有來自Wan的dhcp-client.

find時您應該強調interface=Lan,這樣比較沒爭議.
routeros
回复

使用道具 举报

发表于 2016-5-7 10:22:32 | 显示全部楼层
是哦  肯定有(其它网卡arp信息)
routeros
回复

使用道具 举报

发表于 2016-5-25 08:36:14 | 显示全部楼层
好技术!顶你一个...................收藏了
routeros
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-6-2 22:44 , Processed in 0.069702 second(s), 5 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2023 Discuz! Team.

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