In the Jpcap experiment, the running program always reported an error, the information is as follows:
Error statement:
jpcap = JpcapCaptor.openDevice(devices[0],caplen, promiscCheck,20);
The result of getPacket() function execution has not been null, and no answer has been found on the Internet
Finally, we found that it was the jpcap.jar package. We must use the latest!!!
If it still doesn't work, consider whether the file matches the computer version, that is, 32-bit or 64 bit.
jpcap.jar and jpcap.dll may not be available on the official website. If necessary, you can download them from the following website:
https://github.com/zz2summer/jpcap.git
Attachment: jpcap packet capturing test program (the detailed process will be recorded when there is time):
import jpcap.JpcapCaptor; import jpcap.NetworkInterface; import jpcap.packet.IPPacket; import jpcap.packet.Packet; import java.io.IOException; public class IPPacketTest { public static void main(String[] args) throws IOException { //-----------Step 1 bind network card device--------------- //Returns a list of network devices NetworkInterface[] devices = JpcapCaptor.getDeviceList(); for(NetworkInterface n : devices){ System.out.println(n.name + " | " + n.description ); } System.out.println("-------------------------------------"); JpcapCaptor jpcap = null; int caplen = 1514; boolean promiscCheck = true; //Cappen limits the number of first bytes in a packet to be extracted each time it receives data //Promise: set whether to mix mode. In hybrid mode, all packets will be accepted. If the packet filter function setFilter() is called later, it will not work //This parameter is mainly used for processPacket() method to specify the timeout time jpcap = JpcapCaptor.openDevice(devices[0],caplen, promiscCheck,20); //--------------------Step 2 grab the bag------------------ int i=0; while( i < 10 ){ Packet packet = jpcap.getPacket(); String protocol = null; if(packet instanceof IPPacket && ((IPPacket)packet).version==4){ i++; IPPacket ip = (IPPacket)packet; //Force packet to IP packet System.out.println("Edition: IPv4"); System.out.println("Priority:" + ip.priority); System.out.println("Differentiated services: maximum throughput:" + ip.t_flag); System.out.println("Differentiated services: highest reliability:" + ip.r_flag); System.out.println("Length:" + ip.length); System.out.println("Identification:" + ip.ident); System.out.println("DF:Don't Fragment:" + ip.dont_frag); System.out.println("MF:More Fragment:" + ip.more_frag); System.out.println("Slice offset:" + ip.offset); System.out.println("Lifetime:" + ip.hop_limit); switch (ip.protocol){ case 1:protocol = "ICMP";break; case 2:protocol = "IGMP";break; case 6:protocol = "TCP";break; case 8:protocol = "EGP";break; case 9:protocol = "IGP";break; case 17:protocol = "UDP";break; case 41:protocol = "IPv6";break; case 89:protocol = "OSPF";break; default:break; } System.out.println("Agreement:" + protocol); System.out.println("source IP: " + ip.src_ip.getHostAddress()); System.out.println("objective IP:" + ip.dst_ip.getHostAddress()); System.out.println("Source host name:" + ip.src_ip); System.out.println("Destination host name:" + ip.dst_ip); System.out.println("----------------------------------------------"); } } } }