简体   繁体   English

Mikrotik 脚本问题 - 如何将 ARP 列表中的 ip 和 mac 地址添加到 dhcp - 服务器/租约??? (请帮忙)

[英]Mikrotik Scripting Question - How to add ip's and mac addresses from ARP list to dhcp - server / leases??? (Please Help)

I was wondering if you can help me with the following: I am using Mikrotik scripting on Winbox64, and I want to basically add all the ip's and their mac addresses to dhcp-server leases from the ARP list我想知道您是否可以帮助我解决以下问题:我在 Winbox64 上使用 Mikrotik 脚本,我想基本上将所有 ip 及其 mac 地址添加到 ARP 列表中的 dhcp-server 租约

I am using currently a command on Winbox64 Mikrotik terminal: ip dhcp-server lease > add address=xxx.xx.xx.xx mac-address=xx:xx:xx:xx:xx:xx, so it adds manually each address individually, but I want to move all of them automatically, with perhaps a code loop.我目前在 Winbox64 Mikrotik 终端上使用一个命令:ip dhcp-server lease > add address=xxx.xx.xx.xx mac-address=xx:xx:xx:xx:xx:xx,所以它单独手动添加每个地址,但我想自动移动所有这些,也许有一个代码循环。

Would it be possible ?这有没有可能 ? and if so, how would the code be constructed ?如果是这样,代码将如何构建? I was thinking foreach loop, but still not sure... Forgive me if it's too obvious I am only a beginner on this, and I spent some time figuring it out我在考虑 foreach 循环,但仍然不确定......如果太明显了,请原谅我只是这方面的初学者,我花了一些时间弄清楚

Thank you in advance!先感谢您!

This should be the start of something.这应该是一些事情的开始。 Loop throught the arp.循环遍历arp。 if the mac doesn't exist in leases add the lease.如果租约中不存在 mac,则添加租约。

:local leaseexists

:foreach ARPID in=[/ip arp find] do={


:local ipaddr [/ip arp get $ARPID address]
:local macaddr [/ip arp get $ARPID mac-address]
:local iface [/ip arp get $ARPID interface]


:if ( $macaddr~":" ) do={

    :local leaseexists 0;

    :foreach LEASEID in=[/ip dhcp-server lease find where mac-address="$macaddr"] do={
        :set leaseexists 1
    }

    :if ( $leaseexists = 0 &&  $iface = "INSIDE") do={

        :local date [/system clock get date];
        :local time [/system clock get time];

        /ip dhcp-server lease add address=$ipaddr mac-address=$macaddr server=all comment="arp-to-lease {*date:$date*} {*time:$time*}"

        :foreach LEASEID in=[/ip dhcp-server lease find where mac-address="$macaddr"] do={
            /tool fetch url="http://notify.updateserver.net/notify/lease/$LEASEID" keep-result=no
        }
 
    } 

}

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM