~~821 2022-04-07 17:05 采纳率: 100%
浏览 28
已结题

使用正则表达式提取并显示使用Python的所有接口的接口和方法状态


  •     Copyright (C) 2014-2018 Huawei Technologies Co., Ltd.         *
    
  •                       All rights reserved.                        *
    
  •           Without the owner's prior written consent,              *
    
  •    no decompiling or reverse-engineering shall be allowed.        *
    

Info: The max number of VTY users is 10, and the number
of current VTY users on line is 1.
The current login time is 2022-04-07 08:55:10+00:00.
dis interface brief
2022-04-07 08:55:10.620
PHY: Physical
*down: administratively down
(l): loopback
(s): spoofing
(b): BFD down
(d): Dampening Suppressed
InUti/OutUti: input utility/output utility
Interface PHY Protocol InUti OutUti inErrors outErrors
GigabitEthernet0/0/0 up up 0% 0% 0 0
GigabitEthernet1/0/0 up down 0% 0% 0 0
GigabitEthernet1/0/1 down down 0% 0% 0 0
GigabitEthernet1/0/2 down down 0% 0% 0 0
GigabitEthernet1/0/3 down down 0% 0% 0 0
GigabitEthernet1/0/4 down down 0% 0% 0 0
GigabitEthernet1/0/5 down down 0% 0% 0 0
GigabitEthernet1/0/6 down down 0% 0% 0 0
NULL0 up up(s) 0% 0% 0 0
Virtual-if0 up up(s) -- -- 0 0

用正则表达式将里面的接口信息interface phy 和 protocal 提取出来

  • 写回答

2条回答 默认 最新

  • CSDN专家-HGJ 2022-04-07 17:22
    关注

    试试这样:

    import re
    import pandas as pd
    col=re.findall('(?:Interface).*',s,re.M)[0]
    data=re.findall('(?:outErrors)(.*)',s,re.M|re.S)[0].strip()
    df=pd.DataFrame(data=[d.split() for d in data.split('\n')],columns=col.split())
    print(df)
    
    Interface   PHY Protocol InUti OutUti inErrors outErrors
    0  GigabitEthernet0/0/0    up       up    0%     0%        0         0
    1  GigabitEthernet1/0/0    up     down    0%     0%        0         0
    2  GigabitEthernet1/0/1  down     down    0%     0%        0         0
    3  GigabitEthernet1/0/2  down     down    0%     0%        0         0
    4  GigabitEthernet1/0/3  down     down    0%     0%        0         0
    5  GigabitEthernet1/0/4  down     down    0%     0%        0         0
    6  GigabitEthernet1/0/5  down     down    0%     0%        0         0
    7  GigabitEthernet1/0/6  down     down    0%     0%        0         0
    8                 NULL0    up    up(s)    0%     0%        0         0
    9           Virtual-if0    up    up(s)    --     --        0         0
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月20日
  • 已采纳回答 4月12日
  • 创建了问题 4月7日

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大