~~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日

悬赏问题

  • ¥50 求解vmware的网络模式问题
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?