when I capture a specific packet I can't reproduce the same thing using the same ping. ( for example when you run the project and you go the cmd "ping somethingthatdoesntwork.comm" result : couldn't reach the page, the second time you do the same ping nothing happens.
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("_______________________________________");
}
}
}