我的任务是读取文本文件中特定范围的行,这是通过msinfo32 /report msinfo32.txt
在Windows机器中生成的,此文件的内容是GIANT - 2兆字节的文本!
我必须阅读特定的行并按顺序“组织”它们,硬件信息分为CPU,OS,内存和其他部分。现在我需要检索网络及其驱动程序信息并将其输出为字符串(或字符串数组)。
生成的msinfo32.txt看起来像这样(缩短版本。在提供的部分之间还有更多部分!):
[Keyboard]
Item Value
Description USB Input Device
Name Enhanced (101- or 102-key)
Layout 00000409
Number of Function Keys 12
Driver c:\windows\system32\drivers\hidusb.sys (10.0.14393.82, 37.50 KB (38,400 bytes), 20-Nov-16 21:10)
[Pointing Device]
Item Value
Hardware Type USB Input Device
Status OK
Driver c:\windows\system32\drivers\hidusb.sys (10.0.14393.82, 37.50 KB (38,400 bytes), 20-Nov-16 21:10)
[Modem]
Item Value
[Network]
[Adapter]
Item Value
Name [00000000] Microsoft Kernel Debug Network Adapter
Adapter Type Not Available
Product Type Microsoft Kernel Debug Network Adapter
Index 0
Service Name kdnic
IP Address Not Available
IP Subnet Not Available
Default IP Gateway Not Available
DHCP Enabled Yes
DHCP Server Not Available
DHCP Lease Expires Not Available
DHCP Lease Obtained Not Available
MAC Address Not Available
Driver c:\windows\system32\drivers\kdnic.sys (6.1.0.0, 24.50 KB (25,088 bytes), 16-Jul-16 14:41)
Name [00000001] Realtek PCIe GBE Family Controller
Adapter Type Ethernet 802.3
Product Type Realtek PCIe GBE Family Controller
Installed Yes
PNP Device ID PCI\VEN_10EC&DEV_8168&SUBSYS_79961462&REV_15\4&1C0E5B7D&0&00E0
Last Reset 12-May-17 12:54
Index 1
Service Name rt640x64
IP Address ???.???.???.???, ????::????:????:????:????
IP Subnet 255.255.255.0, 64
Default IP Gateway ???.???.???.1
DHCP Enabled Yes
DHCP Server ???.???.???.1
DHCP Lease Expires 23-May-17 02:58
DHCP Lease Obtained 22-May-17 02:58
MAC Address ??:??:??:??:??:??
I/O Port 0x0000D000-0x0000D0FF
Memory Address 0xDF104000-0xDF104FFF
Memory Address 0xDF100000-0xDF103FFF
IRQ Channel IRQ 16
Driver c:\windows\system32\drivers\rt640x64.sys (9.1.404.2015, 576.00 KB (589,824 bytes), 16-Jul-16 14:41)
[Protocol]
Item Value
Name Hyper-V RAW
Connectionless Service No
[WinSock]
Item Value
File c:\windows\syswow64\wsock32.dll
Size 16.00 KB (16,384 bytes)
Version 10.0.14393.0
[Serial]
从提供的文本文件中,我需要阅读从[网络]结束到[协议]排除的所有内容。
现在我遇到了以下python代码:
msinfo32 = open("msinfo32.txt")
我已经谷歌搜索了我需要的东西,但我只是逐行读取文件并将整个内容导入变量。但是对于2兆字节,我怀疑python是否允许在单个字符串变量中包含2兆字节的文本。