I notice that in RouterOS 7.x.. the UI includes a column for "Bridge Port"
How do I get this listed in terminal?
Neither of these seems to include it in the results:
Code: Select all
/ip/dhcp-server/lease/print
/ip/dhcp-server/lease/print detail
/ip/dhcp-server/lease/print
/ip/dhcp-server/lease/print detail
:put [/ip dhcp-server/lease get *1 ]
active-address address-lists block-access dhcp-option-set insert-queue-before queue-type src-mac-address
active-client-id agent-circuit-id blocked disabled last-seen radius status
active-mac-address agent-remote-id client-id dynamic lease-time rate-limit use-src-mac
active-server allow-dual-stack-queue comment expires-after mac-address routes value-name
address always-broadcast dhcp-option host-name parent-queue server
:put [/ip dhcp-server/lease get *1]
.id=*1;
active-address=172.16.1.254;
active-client-id=1:0:50:79:22:68:3;
active-mac-address=00:50:79:22:68:03;
active-server=dhcp1;
address=172.16.1.254;
address-lists=;
blocked=false;
client-id=1:0:50:79:22:68:3;
dhcp-option=;
disabled=false;
dynamic=true;
expires-after=00:07:24;
host-name=VPCS1;
last-seen=2m36s;
mac-address=00:50:79:22:68:03;
radius=false;
server=dhcp1;
status=bound
:put [/ip dhcp-server lease get value-name=bridge-port number=[/ip dhcp-server lease find address=192.168.88.15]]
Output:
input does not match any value of value-name
/ip/dhcp-server/lease/pr detail terse where address=192.168.88.15
Output:
0 D address=192.168.88.15 mac-address=6C:C7:EC:49:6A:70 client-id=1:6c:c7:ec:49:6a:70 address-lists= server=dhcp-bridge dhcp-option= status=bound expires-after=57m29s last-seen=2m31s active-address=192.168.88.15 active-mac-address=6C:C7:EC:49:6A:70 active-client-id=1:6c:c7:ec:49:6a:70 active-server=dhcp-bridge host-name=Galaxy-S8
OK, understood, thanks.Winbox just like in many other places just takes the info from somewhere else, in this case it just compares the lease mac address with bridge host table entries and shows the port.
:if ($leaseBound = 1) do={
:do {
:local deviceName [/system identity get name];
/ip dhcp-server lease
:local hostName [get value-name=host-name number=[find address=$leaseActIP]]
:local Comment [get value-name=comment number=[find address=$leaseActIP]]
/interface/bridge/host
:local interFace [get [find mac-address=$leaseActMAC] on-interface]
# START Send Telegram Module
:local MessageText "\E2\84\B9 <b>$deviceName: Info DHCP</b> %0D%0A Name: $hostName \
%0D%0A IP: $leaseActIP %0D%0A MAC: $leaseActMAC %0D%0A Interface: $interFace %0D%0A $Comment"
:local SendTelegramMessage [:parse [/system script get MyTGBotSendMessage source]]
$SendTelegramMessage MessageText=$MessageText
# END Send Telegram Module
:log warning "DHCP Alert: $hostName [ $leaseActMAC ] is connect to $interFace"
} on-error={:log error "Telegram notification failure"}
}
Bravo!!!I share with you my script [...]
/ip dhcp-server lease
:foreach id in=[find where [:typeof $"active-address"]="ip"] do={
:local dhcplease "$[get $id]"
:local mac "$[get $id active-mac-address]"
:local bridgeport
:do {
:set $bridgeport [/interface bridge host get [find mac-address=$mac] interface]
} on-error={
}
:set ( "$dhcplease"->"bridge-port" ) "$bridgeport"
:put "$dhcplease"
}
[find where active-address~"."]
[find where [:typeof $"active-address"]="ip"]
@rextended
I did not see any way around the on-error on this, since not all mac address do have a bridge port.
But if you have any idea, they are welcome![]()
/ip dhcp-server lease
:foreach id in=[find where [:typeof $"active-address"]="ip"] do={
:local activeMAC [get $id active-mac-address]
:local if "undefined"
:local outstring "undefined"
/interface bridge host
:local searchresult [find where mac-address=$activeMAC]
:if ([:len $searchresult] > 0) do={
:set if [get $searchresult on-interface]
:set outstring "For bridge host table the $activeMAC is coming from $if"
} else={
:set outstring "Not find any result on bridge host table with MAC $activeMAC"
/ip arp
:set searchresult [find where mac-address=$activeMAC]
:if ([:len $searchresult] > 0) do={
:set if [get ($searchresult->0) interface]
:set outstring "$outstring, but for ARP table $activeMAC is coming from $if"
} else={
:set outstring "$outstring, neither on ARP table."
}
}
:put $outstring
}
Cleaned again, removed inconsistencies and tested on v7.Thanks rextended, script updated.