正在从错误的区域捕获数据。它从 eth1 而不是 eth0 捕获 ip 地址字段和子网。我不明白为什么会这样。我也尝试过matcher.find(0),但得到了相同的结果。
String[] dataNames = new String[]{"eth0Ip", "eth0Subnet"}
dataExtractionPattern = Pattern.compile("eth0 .*inet (?<eth0Ip>\\S+) mask (?<eth0Subnet>\\S+)",Pattern.DOTALL);
Matcher matcher = dataExtractionPattern.matcher(receivedDataString);
if (matcher.find()) {
for (String key : dataNames) {
String dataValue;
dataValue = matcher.group(key);
extractedData.put(key, dataValue);
}
hasData = true;
}
输入字符串为:
lo0 链接类型:本地环回队列:无
inet 127.0.0.1 掩码 255.255.255.255
运行环回
MTU:1500 公制:1 VR:0
RX 数据包:4 mcast:0 错误:0 丢弃:1
TX 数据包:4 mcast:0 错误:0
碰撞:0 不支持的原型:0
RX 字节:172 TX 字节:172
eth0 链接类型:以太网 HWaddr 00:25:f2:5e:9c:34 队列:无
inet 10.1.2.2 掩码 10.1.2.1 广播 255.255.255.254
运行广播
MTU:1000 公制:1 VR:0
RX 数据包:0 mcast:0 错误:0 丢弃:0
TX 数据包:0 mcast:0 错误:0
碰撞:0 不支持的原型:0
RX 字节:0 TX 字节:0
eth1 链接类型:以太网 HWaddr 00:25:f2:5e:9c:33 队列:无
inet 192.168.200.51 掩码 255.255.255.0 广播 192.168.200.255
正在运行的广播
MTU:1500 公制:1 VR:0
RX 数据包:0 mcast:0 错误:0 丢弃:0
TX 数据包:0 mcast:0 错误:0
碰撞:0 不支持的原型:0
RX 字节:0 TX 字节:0
对于 eth0 ip,它错误地捕获 192.168.200.51 和掩码 255.255.255.0