当我捕获特定数据包时,我无法使用相同的ping重现相同的事情。 (例如,当你运行项目并且你去cmd" ping somethatdoesntwork.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("_______________________________________");
}
}
}