# -*- coding:utf-8 -*-
from ncclient import manager
import xmltodict
# NETCONF 连接信息
ac_ip_address = 'ip'
ac_port_number = '830' 默认端口830
ac_username = '账号'
ac_password = '密码'
# 构建 NETCONF 连接
with manager.connect(
host=ac_ip_address,
port=ac_port_number,
username=ac_username,
password=ac_password,
hostkey_verify=False,
device_params={'name': 'h3c'},
allow_agent=False,
look_for_keys=False,
timeout=300
) as m:
# 构建 XML 查询,查看ac下ap的信息
filter_xml = '''
<top xmlns="http://www.h3c.com/netconf/data:1.0">
<AP>
<ManualAP>
<AP>
<Name></Name>
<Model></Model>
<CfgSerialID></CfgSerialID>
<CfgMacAddress></CfgMacAddress>
<RadioNum></RadioNum>
<Status></Status>
</AP>
</ManualAP>
</AP>
</top>
'''
# 发送 NETCONF 查询请求,h3c要加filter=('subtree过滤参数,不然数据出不来response = xmltodict.parse(m.get(filter=('subtree', filter_xml)).data_xml) #xmltodict把xml转为dict
ap_info = response.get('data')
h3c AC netconf
于 2023-12-07 19:40:49 首次发布
本文介绍了如何通过Python的ncclient库连接到H3C设备,执行NETCONF查询,获取AP相关信息,包括名称、型号等,使用XMLtodict处理XML响应。
Python3.8
Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本
您可能感兴趣的与本文相关的镜像
Python3.8
Conda
Python
Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

288

被折叠的 条评论
为什么被折叠?



