<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python script to get all mac address against an interface in a single excel cell in Controllers</title>
    <link>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4100087#M1124</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://community.cisco.com/t5/user/viewprofilepage/user-id/1017682" target="_self"&gt;&lt;SPAN class=""&gt;msdaniluk,&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;This doesn't provide what we need. This lists the mac addresses for an interface in separate rows. What we are looking for is to write mac addresses against an interface in a single cell.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;Thank you.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 09 Jun 2020 13:40:44 GMT</pubDate>
    <dc:creator>pfillips@gmail.com</dc:creator>
    <dc:date>2020-06-09T13:40:44Z</dc:date>
    <item>
      <title>Python script to get all mac address against an interface in a single excel cell</title>
      <link>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4098756#M1118</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am using Netmiko and textfsm to get an output of all the interface status and the mac address table. The final aim is to combine the interface status and mac address table output and map all the mac addresses against an interface in one excel cell using openpyxl. The script works if there is a single mac address against an interface but for an interface with multiple mac addresses the script overwrites the previous mac addresses and put the last one in the excel cell.&lt;/P&gt;&lt;P&gt;Appreciate any assistance.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jun 2020 01:38:31 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4098756#M1118</guid>
      <dc:creator>pfillips11</dc:creator>
      <dc:date>2020-06-07T01:38:31Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to get all mac address against an interface in a single excel cell</title>
      <link>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4098764#M1119</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Could you post your current implementation of code?</description>
      <pubDate>Sun, 07 Jun 2020 03:13:04 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4098764#M1119</guid>
      <dc:creator>ngkin2010</dc:creator>
      <dc:date>2020-06-07T03:13:04Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to get all mac address against an interface in a single excel cell</title>
      <link>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4098798#M1120</link>
      <description>&lt;P&gt;here is the git source you can play with the script how you like your desired output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/routetehpacketz/cisco-ip-trace" target="_blank"&gt;https://github.com/routetehpacketz/cisco-ip-trace&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jun 2020 07:53:55 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4098798#M1120</guid>
      <dc:creator>balaji.bandi</dc:creator>
      <dc:date>2020-06-07T07:53:55Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to get all mac address against an interface in a single excel cell</title>
      <link>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4098822#M1121</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/149327"&gt;@pfillips11&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Personally I prefer using pandas for writing to xls. Feels more natural and straight forward. Here is an example of your scenario (mac table to xls):&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;import pandas as pd&lt;BR /&gt;from &lt;/SPAN&gt;netmiko &lt;SPAN&gt;import &lt;/SPAN&gt;Netmiko&lt;BR /&gt;&lt;SPAN&gt;from &lt;/SPAN&gt;getpass &lt;SPAN&gt;import &lt;/SPAN&gt;getpass&lt;BR /&gt;&lt;BR /&gt;password = getpass()&lt;BR /&gt;net_connect = Netmiko(&lt;SPAN&gt;host&lt;/SPAN&gt;=&lt;SPAN&gt;'172.16.10.10'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;username&lt;/SPAN&gt;=&lt;SPAN&gt;'admin'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;password&lt;/SPAN&gt;=password&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;device_type&lt;/SPAN&gt;=&lt;SPAN&gt;'cisco_nxos'&lt;/SPAN&gt;)&lt;BR /&gt;mac_table = net_connect.send_command(&lt;SPAN&gt;"show mac address-table"&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;use_textfsm&lt;/SPAN&gt;=&lt;SPAN&gt;True&lt;/SPAN&gt;)&lt;BR /&gt;mac_data = {&lt;SPAN&gt;'mac'&lt;/SPAN&gt;:  [entry[&lt;SPAN&gt;'mac'&lt;/SPAN&gt;] &lt;SPAN&gt;for &lt;/SPAN&gt;entry &lt;SPAN&gt;in &lt;/SPAN&gt;mac_table]&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;            &lt;SPAN&gt;'interface'&lt;/SPAN&gt;: [entry[&lt;SPAN&gt;'ports'&lt;/SPAN&gt;] &lt;SPAN&gt;for &lt;/SPAN&gt;entry &lt;SPAN&gt;in &lt;/SPAN&gt;mac_table]&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;            &lt;SPAN&gt;'vlan'&lt;/SPAN&gt;: [entry[&lt;SPAN&gt;'vlan'&lt;/SPAN&gt;] &lt;SPAN&gt;for &lt;/SPAN&gt;entry &lt;SPAN&gt;in &lt;/SPAN&gt;mac_table]&lt;BR /&gt;            }&lt;BR /&gt;&lt;BR /&gt;df = pd.DataFrame(mac_data&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;columns&lt;/SPAN&gt;=&lt;SPAN&gt;list&lt;/SPAN&gt;(mac_data.keys()))&lt;BR /&gt;&lt;BR /&gt;writer = pd.ExcelWriter(&lt;SPAN&gt;'mac_table.xlsx'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;engine&lt;/SPAN&gt;=&lt;SPAN&gt;'xlsxwriter'&lt;/SPAN&gt;)&lt;BR /&gt;df.to_excel(writer&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;'Sheet1'&lt;/SPAN&gt;)&lt;BR /&gt;writer.save()&lt;/PRE&gt;&lt;P&gt;Result:&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;mac&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;interface&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;vlan&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;0&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;c4b2.dead.beee&lt;/TD&gt;&lt;TD&gt;Eth1/49&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;c4b2.dead.beef&lt;/TD&gt;&lt;TD&gt;sup-eth1(R)&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: I added the vlan as well, as I feel it might be needed, but feel free to change the mac_data dictionary.&lt;/P&gt;&lt;P&gt;Hope it helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Stay safe,&lt;/P&gt;&lt;P&gt;Sergiu&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jun 2020 10:02:20 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4098822#M1121</guid>
      <dc:creator>Sergiu.Daniluk</dc:creator>
      <dc:date>2020-06-07T10:02:20Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to get all mac address against an interface in a single excel cell</title>
      <link>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4100077#M1122</link>
      <description>&lt;P&gt;Hi, apologies for the delay. Following is current code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;from netmiko import ConnectHandler,ssh_exception&lt;BR /&gt;from getpass import getpass&lt;BR /&gt;import openpyxl&lt;BR /&gt;from datetime import datetime&lt;BR /&gt;from time import gmtime, strftime&lt;BR /&gt;import os&lt;BR /&gt;import pprint&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#Load the Switch inventory file which has switchname in column 1 and IP address in Column 2. Store the file in same directory where the script is or else define the path using oscwd&lt;BR /&gt;wbswitches = openpyxl.load_workbook("switchenv1.xlsx")&lt;BR /&gt;ws = wbswitches.active&lt;BR /&gt;max_row = ws.max_row&lt;BR /&gt;switches = []&lt;/P&gt;&lt;P&gt;for row in range (2, max_row+1):&lt;BR /&gt;switch = dict()&lt;BR /&gt;switch ['region'] = ws.cell(row= row, column = 1).value&lt;BR /&gt;switch ['country'] = ws.cell(row= row, column = 2).value&lt;BR /&gt;switch ['site_name'] = ws.cell(row= row, column = 3).value&lt;BR /&gt;switch ['device_serial_number'] = ws.cell(row= row, column = 7).value&lt;BR /&gt;switch ['site_address'] = ws.cell(row= row, column = 8).value&lt;BR /&gt;switch ['ip_address'] = ws.cell(row= row, column = 5).value&lt;BR /&gt;switch ['device_name'] = ws.cell(row= row, column = 4).value&lt;BR /&gt;switches.append(switch)&lt;/P&gt;&lt;P&gt;wbswitches.close()&lt;/P&gt;&lt;P&gt;user = input('username:')&lt;BR /&gt;passwd = getpass()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#Load the file portcounters to which the output will be written.Store the file in same directory where the script is or else define the path using oscwd&lt;BR /&gt;actual_time = strftime("%Y-%m-%d_%H-%M-%S")&lt;BR /&gt;logfile_open = open("dot1xLog - " + str(actual_time) + ".txt", "a")&lt;BR /&gt;start_time = datetime.now()&lt;BR /&gt;for switch in switches:&lt;BR /&gt;switchname = switch ['device_name']&lt;BR /&gt;switchaddress = switch ['ip_address']&lt;BR /&gt;switchregion = switch ['region']&lt;BR /&gt;switchcountry = switch ['country']&lt;BR /&gt;switchsitename = switch ['site_name']&lt;BR /&gt;switchserialnumber = switch ['device_serial_number']&lt;BR /&gt;switchsiteaddress = switch ['site_address']&lt;BR /&gt;start_time1 = datetime.now()&lt;BR /&gt;print(start_time1,"Collecting",switchname,"@",switchaddress)&lt;BR /&gt;print(start_time1,"Collecting",switchname,"@",switchaddress, file=logfile_open)&lt;/P&gt;&lt;P&gt;if switchname == None:&lt;BR /&gt;switchname = "Blank"&lt;BR /&gt;print (switchname)&lt;/P&gt;&lt;P&gt;swcon = {&lt;BR /&gt;'device_type': "cisco_ios",&lt;BR /&gt;'ip': switchaddress,&lt;BR /&gt;'username': user,&lt;BR /&gt;'password': passwd,&lt;BR /&gt;'secret': passwd,&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;wbwr = openpyxl.load_workbook("dot1x.xlsx")&lt;BR /&gt;ws = wbwr.active&lt;BR /&gt;ws.title = "Interface Type"&lt;BR /&gt;x=1&lt;BR /&gt;mc = ws.max_column&lt;BR /&gt;max_row = ws.max_row&lt;BR /&gt;&lt;BR /&gt;for row in range(2,ws.max_row):&lt;BR /&gt;if ws.cell(row=row, column=1).value == switchname:&lt;BR /&gt;x=row-1&lt;BR /&gt;print("match")&lt;BR /&gt;print(x)&lt;BR /&gt;break&lt;BR /&gt;else:&lt;BR /&gt;x=max_row&lt;BR /&gt;print("no match")&lt;BR /&gt;print(x)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;net_connect = ConnectHandler(**swcon)&lt;BR /&gt;net_connect.enable()&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;output = net_connect.send_command ("show interfaces status", use_textfsm = True)&lt;BR /&gt;output2 = net_connect.send_command ("show mac address-table", use_textfsm = True)&lt;BR /&gt;&lt;BR /&gt;end_time = datetime.now()&lt;BR /&gt;&lt;BR /&gt;print(end_time,"Completed",switchname,"@",switchaddress)&lt;BR /&gt;print(end_time,"Completed",switchname,"@",switchaddress, file=logfile_open)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;for interface in output:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; for macaddress in output2:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if macaddress['destination_port'] == interface['port']:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; x=x+1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ws.cell(row = x, column = 1, value=switchname)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ws.cell(row = x, column = 2, value=switchaddress)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ws.cell(row = x, column = 3, value=switchregion)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ws.cell(row = x, column = 4, value=switchcountry)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ws.cell(row = x, column = 5, value=switchsitename)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ws.cell(row = x, column = 6, value=switchsiteaddress)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ws.cell(row = x, column = 7, value=switchserialnumber)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ws.cell(row = x, column = 8, value=interface['port'])&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ws.cell(row = x, column = 9, value=interface['vlan'])&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ws.cell(row = x, column = 11, value=macaddress['destination_address'])&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;net_connect.disconnect()&lt;BR /&gt;wbwr.save('dot1x.xlsx')&lt;BR /&gt;&lt;BR /&gt;logfile_open.close()&lt;/P&gt;&lt;P&gt;end_time = datetime.now()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above writes to the excel file but only the last MAC address against an interface. The objective is to put all the MAC addresses against an interface in column 11.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jun 2020 13:31:03 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4100077#M1122</guid>
      <dc:creator>pfillips@gmail.com</dc:creator>
      <dc:date>2020-06-09T13:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to get all mac address against an interface in a single excel cell</title>
      <link>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4100080#M1123</link>
      <description>&lt;P&gt;Thank you Balaji. I am a newbie at it. And looking at the code I can not find anything which provides what I need.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jun 2020 13:32:13 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4100080#M1123</guid>
      <dc:creator>pfillips@gmail.com</dc:creator>
      <dc:date>2020-06-09T13:32:13Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to get all mac address against an interface in a single excel cell</title>
      <link>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4100087#M1124</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://community.cisco.com/t5/user/viewprofilepage/user-id/1017682" target="_self"&gt;&lt;SPAN class=""&gt;msdaniluk,&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;This doesn't provide what we need. This lists the mac addresses for an interface in separate rows. What we are looking for is to write mac addresses against an interface in a single cell.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;Thank you.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jun 2020 13:40:44 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4100087#M1124</guid>
      <dc:creator>pfillips@gmail.com</dc:creator>
      <dc:date>2020-06-09T13:40:44Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to get all mac address against an interface in a single excel cell</title>
      <link>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4100279#M1125</link>
      <description>&lt;P&gt;Trying you understand the requirement -&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you want to learn Python code which can meet the requirement&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or you looking on shelf script you run for your requirement?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jun 2020 18:20:13 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4100279#M1125</guid>
      <dc:creator>balaji.bandi</dc:creator>
      <dc:date>2020-06-09T18:20:13Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to get all mac address against an interface in a single excel cell</title>
      <link>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4100595#M1126</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;output = net_connect.send_command ("show interfaces status", use_textfsm = True)
output2 = net_connect.send_command ("show mac address-table", use_textfsm = True)

end_time = datetime.now()

print(end_time,"Completed",switchname,"@",switchaddress)
print(end_time,"Completed",switchname,"@",switchaddress, file=logfile_open)


for interface in output:

      for macaddress in output2:
          if macaddress['destination_port'] == interface['port']:
             x=x+1
             ws.cell(row = x, column = 1, value=switchname)
             ws.cell(row = x, column = 2, value=switchaddress)
             ws.cell(row = x, column = 3, value=switchregion)
             ws.cell(row = x, column = 4, value=switchcountry)
             ws.cell(row = x, column = 5, value=switchsitename)
             ws.cell(row = x, column = 6, value=switchsiteaddress)
             ws.cell(row = x, column = 7, value=switchserialnumber)
             ws.cell(row = x, column = 8, value=interface['port'])
             ws.cell(row = x, column = 9, value=interface['vlan'])

             ws.cell(row = x, column = 11, value=macaddress['destination_address'])

&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Make sure the intention (space) in the above is correct. Your script have the correct logic to list out all the mac address per interfaces. To debug on the issue, you are advised to confirm the library ntc-template would return you a correct data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try to add the below printing for troubleshooting&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;output = net_connect.send_command ("show interfaces status", use_textfsm = True)
output2 = net_connect.send_command ("show mac address-table", use_textfsm = True)

&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;print(output2)&lt;/STRONG&gt;&lt;/FONT&gt;
&lt;FONT color="#FF0000"&gt;# Make sure you got the data return to you have all the mac addresses (not only 1 mac address per port)&lt;BR /&gt;# Please also post the result here (with masking the MAC addresses for confidential purpose)&lt;/FONT&gt;&lt;BR /&gt;
end_time = datetime.now()

print(end_time,"Completed",switchname,"@",switchaddress)
print(end_time,"Completed",switchname,"@",switchaddress, file=logfile_open)

&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have seen that there is a BUG fix for ntc-template on GitHub since 2 months ago. You are advised to update your ntc-template library.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jun 2020 07:27:16 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4100595#M1126</guid>
      <dc:creator>ngkin2010</dc:creator>
      <dc:date>2020-06-10T07:27:16Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to get all mac address against an interface in a single excel cell</title>
      <link>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4108012#M1127</link>
      <description>&lt;P class="lia-indent-padding-left-30px"&gt;Can you please post the desired output?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jun 2020 13:51:13 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4108012#M1127</guid>
      <dc:creator>juan-ruiz</dc:creator>
      <dc:date>2020-06-23T13:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to get all mac address against an interface in a single excel cell</title>
      <link>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4108014#M1128</link>
      <description>&lt;P&gt;I think this is pretty awesome!&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jun 2020 13:52:41 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4108014#M1128</guid>
      <dc:creator>juan-ruiz</dc:creator>
      <dc:date>2020-06-23T13:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to get all mac address against an interface in a single excel cell</title>
      <link>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4108048#M1129</link>
      <description>&lt;P&gt;Thanks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jun 2020 14:38:51 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4108048#M1129</guid>
      <dc:creator>Sergiu.Daniluk</dc:creator>
      <dc:date>2020-06-23T14:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to get all mac address against an interface in a single excel cell</title>
      <link>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4154756#M1130</link>
      <description>&lt;P&gt;could some one help me with this I am getting a couple errors while trying to run the script&amp;nbsp;&lt;/P&gt;&lt;P&gt;line 8, in &amp;lt;module&amp;gt;&lt;BR /&gt;mac_data = {'mac': [entry['mac'] for entry in mac_table],&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;line 8, in &amp;lt;listcomp&amp;gt;&lt;BR /&gt;mac_data = {'mac': [entry['mac'] for entry in mac_table],&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you very much&lt;/P&gt;&lt;P&gt;ps I am just now trying to learn the language&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Sep 2020 16:00:34 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4154756#M1130</guid>
      <dc:creator>Steven King</dc:creator>
      <dc:date>2020-09-21T16:00:34Z</dc:date>
    </item>
    <item>
      <title>Re: Python script to get all mac address against an interface in a sin</title>
      <link>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4681443#M1131</link>
      <description>&lt;P&gt;I know this is an old thread but for anyone struggling to get the code provided by Sergiu to work you need to change the entries as follows:&lt;/P&gt;
&lt;P&gt;mac_data = {'mac': [entry['destination_address'] for entry in mac_table],&lt;BR /&gt;'interface': [entry['destination_port'] for entry in mac_table],&lt;BR /&gt;'vlan': [entry['vlan'] for entry in mac_table]&lt;BR /&gt;}&lt;/P&gt;
&lt;P&gt;The key error is because it is not finding the entry within the text which is output from the switch. Hope this saves someone a couple of hours &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Sep 2022 12:27:45 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-script-to-get-all-mac-address-against-an-interface-in-a/m-p/4681443#M1131</guid>
      <dc:creator>TheRivanKing</dc:creator>
      <dc:date>2022-09-05T12:27:45Z</dc:date>
    </item>
  </channel>
</rss>

