Reply
Highlighted
Regular Member
Posts: 369
Registered: ‎04-15-2014
Kudos: 18
Solutions: 8
Accepted Solution

Scripting a search in MAC address table

Hello,

 

I'm about to write a script that will receive a MAC address as argument and print the port number of the Edgeswitch the device owning this MAC is connected to.

 

This script would be run on a Debian host during off hours.

If possible, I would appreciate to use Python for writing this script.

 

1. What do you recommend ? Shall I use SNMP for this ?

 

2. Shall I prefer Expect and Edgeswitch CLI ? In this case, is there a command to query MAC table without parsing whole show mac-addr-table output ?

 

Best regards

 


Accepted Solutions
Ubiquiti Employee
Posts: 2,516
Registered: ‎05-08-2017
Kudos: 447
Solutions: 367

Re: Scripting a search in MAC address table

[ Edited ]

Hi @oliv,

 

The show mac-addr-table command allows you to specify a MAC address/interface or you can pipe the command to include only certain output. 

 

For example:

(EdgeSwitch) #show mac-addr-table AB:CD:EF:12:34:56

VLAN ID  MAC Address         Interface              IfIndex  Status
-------  ------------------  ---------------------  -------  ------------
1        AB:CD:EF:12:34:56   0/8                    8        Learned

(EdgeSwitch) #show mac-addr-table interface 0/8    

   MAC Address      VLAN ID      Status
-----------------  ---------  ------------
AB:CD:EF:12:34:56     1        Learned

(EdgeSwitch) #show mac-addr-table | include AB:CD:EF

1        AB:CD:EF:12:34:56   0/8                    8        Learned

 

Make sure to enable AAA exec authorization so that you can run privileged mode commands from scripts. Reference post here.

 

Hope that helps!

 

-Ben


Ben Pin - EdgeMAX Support

View solution in original post


All Replies
Ubiquiti Employee
Posts: 2,516
Registered: ‎05-08-2017
Kudos: 447
Solutions: 367

Re: Scripting a search in MAC address table

[ Edited ]

Hi @oliv,

 

The show mac-addr-table command allows you to specify a MAC address/interface or you can pipe the command to include only certain output. 

 

For example:

(EdgeSwitch) #show mac-addr-table AB:CD:EF:12:34:56

VLAN ID  MAC Address         Interface              IfIndex  Status
-------  ------------------  ---------------------  -------  ------------
1        AB:CD:EF:12:34:56   0/8                    8        Learned

(EdgeSwitch) #show mac-addr-table interface 0/8    

   MAC Address      VLAN ID      Status
-----------------  ---------  ------------
AB:CD:EF:12:34:56     1        Learned

(EdgeSwitch) #show mac-addr-table | include AB:CD:EF

1        AB:CD:EF:12:34:56   0/8                    8        Learned

 

Make sure to enable AAA exec authorization so that you can run privileged mode commands from scripts. Reference post here.

 

Hope that helps!

 

-Ben


Ben Pin - EdgeMAX Support

Regular Member
Posts: 369
Registered: ‎04-15-2014
Kudos: 18
Solutions: 8

Re: Scripting a search in MAC address table

This is exactly what I was looking for !

Thank you very much

Reply