Python:获取华为交换机的ARP地址表

from napalm import get_network_driver
from netaddr import IPNetwork, IPAddress
import re
import pandas as pd


driver = get_network_driver('huawei_vrp')
device = driver(hostname='10.20.0.250', username='fsad', password='SWxcf123d~@')
device.open()

# arp = device.get_arp_table()
# mac = device.get_mac_address_table()

cli = 'disp arp interface Vlanif 1020'
send_command = device.cli([cli])
device.close()

arp = send_command[cli]
arp_new = arp.split('\n')
arp_get = []
for i in arp_new:
    if (i.find('10.20') == 0 and i.find('I - ') == -1):
        item =  re.split(r"[ ]+", i)
        arp_get.append(item)

columns = ['IP', 'MAC', 'Expired', 'Type', 'Interface', 'VPN-INSTANCE']
df = pd.DataFrame(arp_get, columns=columns, )
df

输出结果:

点赞

发表回复

电子邮件地址不会被公开。必填项已用 * 标注