我可以编写一个 Java 示例,您可以将其翻译成任何您想要的语言
import java.io.*;
import java.util.*;
class Macs {
public static void main(String...args)throws Exception {
Set<String> macs = loadLines("macs.txt");
Set<String> ips = loadLines("ips.txt");
for(String raw : ips) {
String[] tokens = raw.split("\\s"); // by space
String ip = tokens[0];
String mac = tokens[1];
if(!macs.contains(mac))
System.out.println(raw);
}
}
static Set<String> loadLines(String filename) throws Exception {
Scanner sc = new Scanner(new File(filename));
Set<String> lines = new HashSet<String>();
while(sc.hasNextLine()) {
// substring(1) removes leading $
lines.add(sc.nextLine().substring(1).toLowerCase());
}
return lines;
}
}
将此输出重定向到文件将为您提供结果。
使用以下输入文件
macs.txt
$AA:BB:CC:DD:EE:01
$AA:BB:CC:DD:EE:02
$AA:BB:CF:DD:EE:09
$AA:EE:CF:DD:EE:09
ips.txt
$172.0.0.1 AA:BB:CC:DD:EE:01
$172.0.0.2 AA:BB:CC:DD:EE:02
$172.0.0.2 AA:BB:CC:DD:EE:05
$172.0.0.66 AA:BB:CC:DD:EE:0E
$172.0.0.4 AA:BB:CC:DD:EE:06
$172.0.0.5 AA:BB:CF:DD:EE:09
$172.0.0.6 AA:BB:CC:DD:EE:03
结果:
c:\files\j>java Macs
172.0.0.6 aa:bb:cc:dd:ee:03
172.0.0.66 aa:bb:cc:dd:ee:0e
172.0.0.2 aa:bb:cc:dd:ee:05
172.0.0.4 aa:bb:cc:dd:ee:06