想把下面txt文档中的2001:3001:700:80::1 这些个IP地址 0000-5e00-0101mac地址放到一个表格中。
> IPv6 Address :2001:3001:700:80::1
Link-layer : 0000-5e00-0101 State : REACH
Interface : MEth0/0/0 Age : 2
VLAN : - CEVLAN : -
VPN name : NMS_tenant Is Router : TRUE
Secure FLAG : UN-SECURE Nickname : -
Source IP : -
Destination IP: -
VNI : - BD : -
IPv6 Address : 2001:3001:700:80::16
Link-layer : 94b2-714e-e758 State : REACH
Interface : MEth0/0/0 Age : 16
VLAN : - CEVLAN : -
VPN name : NMS_tenant Is Router : TRUE
Secure FLAG : UN-SECURE Nickname : -
Source IP : -
Destination IP: -
VNI : - BD : -
带该变成这个样子,这里面有很多上面的数据,不仅仅这么多
捣鼓了好长时间还是不行
import re
import openpyxl
from openpyxl import Workbook
ipv6_re=re.compile(r"IPv6 Address :(.*)")
mac_re=re.compile(r"Link-layer :(.*)\s*State.*")
vpn_re=re.compile(r"VPN name : (.*)")
outinterface_re=re.compile(r"Interface :(.*)")
wb=Workbook()
ws=wb.active
with open ("ST-EOR.txt") as f:
for line in f:
data=[i for i in mac_re.findall(line) or ipv6_re.findall(line) or outinterface_re.findall(line) or vpn_re.findall(line)]
ws.append(data)
wb.save("first.xlsx")
wb.close
麻烦补充下我写的东西,万分感谢!
还有一个问题,我想用列表的形式把数据写到excel中。那种方式更方便一些?字典吗?可以字典还没学!