【发布时间】:2020-02-07 03:39:35
【问题描述】:
从下面的配置中,我需要提取主机名和组名邻居 x.x.x.x 信息,
#
-设置系统主机名devicename_ABC
-set protocols bgp group 组名类型内部
-set protocols bgp group 组名邻居 x.x.x.x
-set protocols bgp group 组名邻居 z.z.z.z
#
我在 python 脚本下面写了,但它显示索引错误。请帮我解决这个问题。
Python 脚本:
reDeviceName = re.compile(r'#\s*\n\s*host (\S*)\s*',re.DOTALL)
deviceName = reDeviceName.findall(allText)
regBbpGroup = re.compile(r'\s*bgp group (\S*)\s*',re.DOTALL)
bpGroupList = regBbpGroup.findall(allText)
numBbpGroup = len(bpGroupList)
i = 0
def temp(x):
return x
while i < numBbpGroup:
requiredInfo = list(map(temp,bpGroupList[i]))
requiredInfo.insert(0,deviceName[0]) (index error showing for this line)
bpGroupList = str(requiredInfo[2])
i = i + 1
【问题讨论】:
-
可能需要看看
allText里面有什么。 -
所有文本包含以下信息 --set system host-name devicename_ABC -set protocols bgp group Group-name type internal -set protocols bgp group Group-name neighbor xxxx -set protocols bgp group Group-name neighbor zzzz
-
我认为这不是用于
reDeviceName的正确正则表达式。您希望该模式返回什么? -
我想从路由器命令行收集设备名称和 BGP 组名称应该是正确的命令
标签: python python-3.x index-error