Page 1 of 1

Getting Bridge Port from DHCP Leases in Terminal

Posted: Wed Jan 26, 2022 4:04 am
by awonglk
Hi,

I notice that in RouterOS 7.x.. the UI includes a column for "Bridge Port"
BridgePort.JPG
How do I get this listed in terminal?

Neither of these seems to include it in the results:
/ip/dhcp-server/lease/print
/ip/dhcp-server/lease/print detail
Seems useful to help me get which CAP interface a particular DHCP client is associated with.

Re: Getting Bridge Port from DHCP Leases in Terminal

Posted: Wed Jan 26, 2022 9:10 am
by Jotne
This is clearly a bug on 7.1.1 and 7.2.rc1. Please report this to support@mikrotik.com

I did try to find it and its not in termial.
: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     
"Bridge Port" that are shown in Winbox are not to find in CLI
 :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

Re: Getting Bridge Port from DHCP Leases in Terminal

Posted: Wed Feb 16, 2022 2:36 pm
by mane
Same here, hap ac3 with 7.1.2 and half of leases are without a bridge port in DHCP Server > Leases

Re: Getting Bridge Port from DHCP Leases in Terminal

Posted: Fri Dec 02, 2022 12:53 pm
by diamuxin
Hi,

has this bug been fixed yet?
has anyone managed to fix it?

With version 7.6 it still persists,
: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
In Winbox if this field appears:

Image

BR.

Re: Getting Bridge Port from DHCP Leases in Terminal

Posted: Fri Dec 02, 2022 2:39 pm
by Jotne
Should be easy to fix, så MT please fix.

Re: Getting Bridge Port from DHCP Leases in Terminal

Posted: Fri Dec 02, 2022 2:58 pm
by diamuxin
I have written an email to support but have had no response.

:( :(

BR.

Re: Getting Bridge Port from DHCP Leases in Terminal

Posted: Tue Dec 13, 2022 12:07 pm
by diamuxin
No solution? A pity that no one from Mikrotik even responds.

Thank you.

Re: Getting Bridge Port from DHCP Leases in Terminal

Posted: Tue Dec 13, 2022 12:41 pm
by Jotne
Normal its the other way around. You see some in CLI that are not shown in WinBox.
This should be easy to fix, but since 7.7 are in RC state, I guess it will not be fixed in 7.7 version.

Re: Getting Bridge Port from DHCP Leases in Terminal

Posted: Tue Dec 13, 2022 1:41 pm
by mrz
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.

Re: Getting Bridge Port from DHCP Leases in Terminal

Posted: Tue Dec 13, 2022 2:18 pm
by diamuxin
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.
OK, understood, thanks.

BR.

Re: Getting Bridge Port from DHCP Leases in Terminal

Posted: Tue Dec 13, 2022 7:16 pm
by diamuxin
Hello,

I share with you my script with the solution to obtain the "bridge-port" that appears in Leases and that is obtained from the Bridge Hosts table.

The script is located in my DHCP-Server and works correctly.
: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"}

}
BR.

Re: Getting Bridge Port from DHCP Leases in Terminal

Posted: Tue Dec 13, 2022 8:55 pm
by rextended
I share with you my script [...]
Bravo!!!

Re: Getting Bridge Port from DHCP Leases in Terminal

Posted: Tue Dec 13, 2022 10:05 pm
by Jotne
Here is my version that I may implement in the Splunk to get all active DHCP leases with bridge port.
It injects the bridge-port inn to the dhcp lease array.
/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"
}
@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 :)

Re: Getting Bridge Port from DHCP Leases in Terminal

Posted: Tue Dec 13, 2022 11:31 pm
by rextended
I check but...

while I read the rest... this??? (I understand why...)
[find where active-address~"."]

is this....
[find where [:typeof $"active-address"]="ip"]

for coherence must be used active-mac-address and not mac-address than on static lease can be altered later.... ;)

also, for the same reason, must be checked real "on-interface" than "interface"...

Re: Getting Bridge Port from DHCP Leases in Terminal

Posted: Tue Dec 13, 2022 11:54 pm
by Jotne
Thanks rextended, script updated.

Re: Getting Bridge Port from DHCP Leases in Terminal

Posted: Tue Dec 13, 2022 11:54 pm
by rextended
@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 :)

Ehhh....

/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
}

Re: Getting Bridge Port from DHCP Leases in Terminal

Posted: Wed Dec 14, 2022 12:00 am
by rextended
The previous script is updated, because on ARP table is possible have multiple results for more than one IP for same MAC, and I fix the probable error.

Tested only on v6.

Re: Getting Bridge Port from DHCP Leases in Terminal

Posted: Wed Dec 14, 2022 12:12 am
by rextended
Thanks rextended, script updated.
Cleaned again, removed inconsistencies and tested on v7.

If you tried the script before reading this, use the new version.

My script check also the ARP table, because not everytime the DHCP server is on one bridge... ;)