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

使用正则表达式提取并显示使用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日

悬赏问题

  • ¥15 求Houdini使用行家,付费。价格面议。
  • ¥15 AttributeError: 'EasyDict' object has no attribute 'BACKUP_DB_INFO'
  • ¥15 前端高拍仪调用问题报错
  • ¥15 想用octave解决这个数学问题
  • ¥15 Centos新建的临时ip无法上网,如何解决?
  • ¥15 海康威视如何实现客户端软件对设备语音请求的处理。
  • ¥15 支付宝h5参数如何实现跳转
  • ¥15 MATLAB代码补全插值
  • ¥15 Typegoose 中如何使用 arrayFilters 筛选并更新深度嵌套的子文档数组信息
  • ¥15 CF1927D 求Hack