读取NE40E接口信息

'''

python


import re
import pandas as pd
data = []
final_data=[]
current={'接口':'',"VLAN":'',"VPN":'',"类型1":'',"IPv4地址":'',"类型2":'',"IPv6地址":'',"OSPFv3进程":''}
with open('1.txt') as f:
    for line in f.readlines():
        if line.startswith("interface NULL0"):
            break
        if line.startswith('interface '):
            if len(current["IPv4地址"]) == 0 and len(current["IPv6地址"]) == 0:
                current = {'接口':'',"VLAN":'',"VPN":'',"类型1":'',"IPv4地址":'',"类型2":'',"IPv6地址":'',"OSPFv3进程":''}
            else:
                data.append(current)
                current = {'接口':'',"VLAN":'',"VPN":'',"类型1":'',"IPv4地址":'',"类型2":'',"IPv6地址":'',"OSPFv3进程":''}
        if line.startswith("interface "):
            current["接口"]=re.findall(r"interface (.*)",line)[0]
        elif line.startswith(' vlan-type dot1q '):
            current["VLAN"]=re.findall(r" vlan-type dot1q (.*)",line)[0]
        elif line.startswith(" ip binding vpn-instance "):
            current["VPN"]=re.findall(r" ip binding vpn-instance (.*)",line)[0]
        elif line.startswith(" ip address "):
            current["IPv4地址"]=re.findall(r" ip address (.*)",line)[0]
            current["类型1"]="IPv4"
        elif 'ipv6 address auto link-local' in line:
            pass
        elif line.startswith(" ipv6 address "):
            current["IPv6地址"]=re.findall(r" ipv6 address (.*)",line)[0]
            current["类型2"]="IPv6"
        elif line.startswith(' ospfv3 ') and line.endswith(" area 0.0.0.0\n"):
            current["OSPFv3进程"]=re.findall(r" ospfv3 (.*) area 0.0.0.0",line)[0]
data.append(current)
final_data=filter(None,data)
df = pd.DataFrame(data)
df.to_excel('result.xlsx', index=False)

'''

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值