python分析路由器配置文件_Python网络工程师路由器配置解析

我可以使用一些帮助来解析一个配置文件,其中我创建了列表,其中每个列表都有以下格式;来自配置文件(如下所示)。我试图让我的脚本读取配置文件并列出主机名之后的每个接口的详细信息。在PE1-Loopback0-1.1.1.1 255.255.255.255

PE1-GigabitEthernet1.10-205.1.1.1 255.255.255.0

PE1-GigabitEthernet1.999-10.10.1.1 255.255.255.0

PE2-Loopback0-2.2.2.2 255.255.255.255

PE2-GigabitEthernet1.10-205.1.1.2 255.255.255.0

PE2-GigabitEthernet1.999-10.10.1.2 255.255.255.0

我的脚本如下:

^{pr2}$

我的脚本输出:PE1-Loopback0-1.1.1.1 255.255.255.255

PE1-GigabitEthernet1.10-205.1.1.1 255.255.255.0

PE1-GigabitEthernet1.999-10.10.1.1 255.255.255.0

PE1-Loopback0-2.2.2.2 255.255.255.255

PE1-GigabitEthernet1.10-205.1.1.2 255.255.255.0

PE1-GigabitEthernet1.999-10.10.1.2 255.255.255.0

我想我知道为什么我的输出是这样的。第一个for循环(forloop1)为hostname运行一个regex,然后继续执行第二个for循环(forloop2);我认为这就是我的问题所在。第一个循环继续报告PE1,第二个循环继续解析regex参数下的配置文件。我希望第二个循环在看到另一个主机名条目时结束,这样我的脚本就可以解析PE2下的接口详细信息,而不是PE1。在

结果应该如下所示:PE1-Loopback0-1.1.1.1 255.255.255.255

PE1-GigabitEthernet1.10-205.1.1.1 255.255.255.0

PE1-GigabitEthernet1.999-10.10.1.1 255.255.255.0

PE2-Loopback0-2.2.2.2 255.255.255.255

PE2-GigabitEthernet1.10-205.1.1.2 255.255.255.0

PE2-GigabitEthernet1.999-10.10.1.2 255.255.255.0

配置文件:hostname PE1

!

!

interface Loopback0

ip address 1.1.1.1 255.255.255.255

!

interface Tunnel999

ip unnumbered Loopback0

mpls ip

mpls label protocol ldp

tunnel mode mpls traffic-eng

tunnel destination 2.2.2.2

tunnel mpls traffic-eng autoroute announce

tunnel mpls traffic-eng path-option 10 dynamic

tunnel mpls traffic-eng path-selection metric te

tunnel mpls traffic-eng name PE1-TO-PE2

!

interface GigabitEthernet1

no ip address

negotiation auto

ip rsvp bandwidth

!

interface GigabitEthernet1.10

encapsulation dot1Q 10

ip address 205.1.1.1 255.255.255.0

mpls ip

mpls label protocol ldp

mpls traffic-eng tunnels

mpls traffic-eng administrative-weight 100

ip rsvp bandwidth 99

!

interface GigabitEthernet1.999

encapsulation dot1Q 999

ip address 10.10.1.1 255.255.255.0

!

hostname PE2

!

!

interface Loopback0

ip address 2.2.2.2 255.255.255.255

!

interface Tunnel999

ip unnumbered Loopback0

mpls ip

mpls label protocol ldp

tunnel mode mpls traffic-eng

tunnel destination 2.2.2.2

tunnel mpls traffic-eng autoroute announce

tunnel mpls traffic-eng path-option 10 dynamic

tunnel mpls traffic-eng path-selection metric te

tunnel mpls traffic-eng name PE1-TO-PE2

!

interface GigabitEthernet1

no ip address

negotiation auto

ip rsvp bandwidth

!

interface GigabitEthernet1.10

encapsulation dot1Q 10

ip address 205.1.1.2 255.255.255.0

mpls ip

mpls label protocol ldp

mpls traffic-eng tunnels

mpls traffic-eng administrative-weight 100

ip rsvp bandwidth 99

!

interface GigabitEthernet1.999

encapsulation dot1Q 999

ip address 10.10.1.2 255.255.255.0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值