Community discussions

MikroTik App
 
awonglk
newbie
Topic Author
Posts: 33
Joined: Sat Oct 31, 2015 3:43 pm

Getting Bridge Port from DHCP Leases in Terminal

Wed Jan 26, 2022 4:04 am

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.
You do not have the required permissions to view the files attached to this post.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Getting Bridge Port from DHCP Leases in Terminal

Wed Jan 26, 2022 9:10 am

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
 
mane
just joined
Posts: 1
Joined: Tue Feb 15, 2022 10:31 pm
Location: Italy

Re: Getting Bridge Port from DHCP Leases in Terminal

Wed Feb 16, 2022 2:36 pm

Same here, hap ac3 with 7.1.2 and half of leases are without a bridge port in DHCP Server > Leases
 
User avatar
diamuxin
Member
Member
Posts: 319
Joined: Thu Sep 09, 2021 5:46 pm
Location: Alhambra's City

Re: Getting Bridge Port from DHCP Leases in Terminal

Fri Dec 02, 2022 12:53 pm

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.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Getting Bridge Port from DHCP Leases in Terminal

Fri Dec 02, 2022 2:39 pm

Should be easy to fix, så MT please fix.
 
User avatar
diamuxin
Member
Member
Posts: 319
Joined: Thu Sep 09, 2021 5:46 pm
Location: Alhambra's City

Re: Getting Bridge Port from DHCP Leases in Terminal

Fri Dec 02, 2022 2:58 pm

I have written an email to support but have had no response.

:( :(

BR.
 
User avatar
diamuxin
Member
Member
Posts: 319
Joined: Thu Sep 09, 2021 5:46 pm
Location: Alhambra's City

Re: Getting Bridge Port from DHCP Leases in Terminal

Tue Dec 13, 2022 12:07 pm

No solution? A pity that no one from Mikrotik even responds.

Thank you.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Getting Bridge Port from DHCP Leases in Terminal

Tue Dec 13, 2022 12:41 pm

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.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7038
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Getting Bridge Port from DHCP Leases in Terminal

Tue Dec 13, 2022 1:41 pm

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.
 
User avatar
diamuxin
Member
Member
Posts: 319
Joined: Thu Sep 09, 2021 5:46 pm
Location: Alhambra's City

Re: Getting Bridge Port from DHCP Leases in Terminal

Tue Dec 13, 2022 2:18 pm

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.
 
User avatar
diamuxin
Member
Member
Posts: 319
Joined: Thu Sep 09, 2021 5:46 pm
Location: Alhambra's City

Re: Getting Bridge Port from DHCP Leases in Terminal

Tue Dec 13, 2022 7:16 pm

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.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Getting Bridge Port from DHCP Leases in Terminal

Tue Dec 13, 2022 8:55 pm

I share with you my script [...]
Bravo!!!
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Getting Bridge Port from DHCP Leases in Terminal

Tue Dec 13, 2022 10:05 pm

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 :)
Last edited by Jotne on Tue Dec 13, 2022 11:53 pm, edited 2 times in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Getting Bridge Port from DHCP Leases in Terminal

Tue Dec 13, 2022 11:31 pm

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"...
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Getting Bridge Port from DHCP Leases in Terminal

Tue Dec 13, 2022 11:54 pm

Thanks rextended, script updated.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Getting Bridge Port from DHCP Leases in Terminal

Tue Dec 13, 2022 11:54 pm

@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
}
Last edited by rextended on Wed Dec 14, 2022 12:08 am, edited 2 times in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Getting Bridge Port from DHCP Leases in Terminal

Wed Dec 14, 2022 12:00 am

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.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Getting Bridge Port from DHCP Leases in Terminal

Wed Dec 14, 2022 12:12 am

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... ;)

Who is online

Users browsing this forum: Google [Bot], patrikg, rextended and 23 guests