我在使用正则表达式解析'ipconfig/all'的输出时遇到了一些麻烦。 目前我正在使用RegexBuddy进行测试,但我想在C#.NET中使用正则表达式。解析Windows'ipconfig/all'输出
我的输出是:
Ethernet adapter Yes:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : MAC Bridge Miniport
Physical Address. . . . . . . . . : 02-1F-29-00-85-C9
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : fe80::f980:c9c3:a574:37a%24(Preferred)
Link-local IPv6 Address . . . . . : fe80::f980:c9c3:a574:37a7%24(Preferred)
Link-local IPv6 Address . . . . . : fe80::f980:c9c3:a574:37a8%24(Preferred)
IPv4 Address. . . . . . . . . . . : 10.0.0.1(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.0.0
IPv4 Address. . . . . . . . . . . : 172.16.0.1(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 172.16.0.254
DHCPv6 IAID . . . . . . . . . . . : 520228888
DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-17-1C-CC-CF-00-1F-29-00-85-C9
DNS Servers . . . . . . . . . . . : 192.162.100.15
192.162.100.16
NetBIOS over Tcpip. . . . . . . . : Enabled
到目前为止,我已经写的正则表达式是:
([ -~]+):.+(?:Description\s)(?:\.|\s)+:\s([ -~]+).+(?:Physical Address)(?:\.|\s)+:\s([ -~]+).+(?:DHCP Enabled)(?:\.|\s)+:\s([ -~]+).+(?:(?:Link-local IPv6 Address)(?:\.|\s)+:\s([ -~]+).+Preferred.+)+
的问题是,我想捕获所有有用的领域群体,让他们轻松在C#中,出于某种原因 - 当我捕获多个“本地链接本地IPv6”字段时,它停止工作。
我会感谢任何帮助, 谢谢。
编辑: 另一个问题是,我从远程机器接收ipconfig数据(有一个非托管程序,我没有控制权) - 因此我不能使用WMI或类似的东西来获取ipconfig信息以另一种方式。
为什么RegEx?数据已经存在于一个关键的价值表示法中。 – 2013-03-03 10:02:19