当我捕获特定数据包时,我无法使用相同的 ping 重现相同的内容。(例如,当您运行项目并执行 cmd“ping somethingthatdoesntwork.comm”结果:无法访问该页面时,您第二次执行相同的 ping 操作时没有任何反应。
public class Pcap4jLoop {
public static void main(String[] args)
throws PcapNativeException, IOException, NotOpenException, InterruptedException {
String filter = null;
if (args.length != 0) {
filter = args[0];
}
PcapNetworkInterface nif = new NifSelector().selectNetworkInterface();
if (nif == null) {
System.exit(1);
}
final PcapHandle handle = nif.openLive(65536, PromiscuousMode.NONPROMISCUOUS, 10);
PacketListener listener = new PacketListener() {
public void gotPacket(PcapPacket packet) {
printPacket(packet, handle);
}
};
while (true) {
handle.loop(1, listener);
Thread.sleep(10);
}
}
private static void printPacket(Packet packet, PcapHandle ph) {
StringBuilder sb = new StringBuilder();
if (packet != null)
if (packet.toString().contains("Question") && packet.toString().contains("Authority")) {
System.out.println(packet.toString().split("DNS Header")[1].split("QNAME: ")[1].split("QTYPE")[0]);
if (packet.toString().contains("RCODE: 3")) {
System.out.println("Couldn't reach this page");
}
System.out.println("_______________________________________");
}
}
}