日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Python:通过SNMP协议获取华为交换机的ARP地址表

發布時間:2025/3/11 python 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python:通过SNMP协议获取华为交换机的ARP地址表 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

華為交換機SNMP配置

system-view 進入交換機的配置模式、
[switch]snmp-agent community read huawei 配置community 只讀屬性為huawei
[switch]snmp-agent community write huawei 配置community 可寫屬性為huawei
[switch]snmp-agent sys-info version all 配置版本為所有

# coding=utf-8import systry:from pysnmp.entity.rfc3413.oneliner import cmdgen except Exception as e:print("You need to download pysnmp and pyasn1", e)sys.exit(1)oTable = {"entLogicalCommunity": (1, 3, 6, 1, 2, 1, 47, 1, 2, 1, 1, 4),"entPhysicalModelName": (1, 3, 6, 1, 2, 1, 47, 1, 1, 1, 1, 13, 1),"entLogicalDescr": (1, 3, 6, 1, 2, 1, 47, 1, 2, 1, 1, 2),"dot1dBasePort": (1, 3, 6, 1, 2, 1, 17, 1, 4, 1, 1),"dot1dTpFdbPort": (1, 3, 6, 1, 2, 1, 17, 4, 3, 1, 2),"dot1dBasePortIfIndex": (1, 3, 6, 1, 2, 1, 17, 1, 4, 1, 2),"dot1dTpFdbAddress": (1, 3, 6, 1, 2, 1, 17, 4, 3, 1, 1),"ifDescr": (1, 3, 6, 1, 2, 1, 2, 2, 1, 2),"ifName": (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 1),"ifSpeed": (1, 3, 6, 1, 2, 1, 2, 2, 1, 5),"ifAlias": (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18),"sysName": (1, 3, 6, 1, 2, 1, 1, 5, 0),"sysDescr": (1, 3, 6, 1, 2, 1, 1, 1, 0),"dot3StatsDuplexStatus": (1, 3, 6, 1, 2, 1, 10, 7, 2, 1, 19),"ifAdminStatus": (1, 3, 6, 1, 2, 1, 2, 2, 1, 7),"ifOperStatus": (1, 3, 6, 1, 2, 1, 2, 2, 1, 8),"atPhysAddress": (1, 3, 6, 1, 2, 1, 3, 1, 1, 2),"ipAdEntAddr": (1, 3, 6, 1, 2, 1, 4, 20, 1, 1),"ipAdEntIfIndex": (1, 3, 6, 1, 2, 1, 4, 20, 1, 2),"ARP": (1, 3, 6, 1, 2, 1, 3, 1, 1, 2),"HW": (1, 3, 6, 1, 2, 1, 4, 22, 1, 2) }def walk(dswitch, community, oid):"""This function will return the table of OID's that I am walking"""errorIndication, errorStatus, errorIndex, \generic = cmdgen.CommandGenerator().nextCmd(cmdgen.CommunityData('my-agent', community, mpModel=1),cmdgen.UdpTransportTarget((dswitch, 161)), oid)if errorIndication:return errorIndicationreturn genericentaddr = walk("192.168.80.1", "huawei", oTable["HW"])arp_table = []"""======主函數======""" # Press the green button in the gutter to run the script. if __name__ == '__main__':for i in entaddr:temp = ''for j in i:temp += str(j)temp = temp.replace("SNMPv2-SMI::mib-2.4.22.1.2.", "")temp = temp[temp.find('.') + 1:]temp = temp.split(' = ')arp_table.append(temp)# 打印ARP表for list_IP_MAC in arp_table:print(list_IP_MAC)

總結

以上是生活随笔為你收集整理的Python:通过SNMP协议获取华为交换机的ARP地址表的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。