Use pcap4j to detect a mac address of remote host
I searched the whole website, and I found no solution provided to detect a mac address of remote host under same subnetwork.
So I created this project.
I used pcap4j to send and filtering packets. and for a IPv4 address, I used arp protocol related function to extract the mac address. and for a IPv6 address, I used ndp (neighbor discovery) protocol related function to extract the mac address.
- pcap4j 1.7.3
- libpcap. (ready for use version files has been uploaded into libpcapfiles)
- gradle build (no dep jars included)
- gradle fatjar (recommended, dep jars included)
on linux, you can load the libpcap directly without install anything
java -Dorg.pcap4j.core.pcapLibName=libpcap.so -cp .:networkutils-all-0.2.jar Test 192.168.170.149
On windows, the npcap is required to be installed. (no reboot required)
java -Dorg.pcap4j.core.pcapLibName=wpcap.dll -Dorg.pcap4j.core.packetLibName=Packet.dll -cp .;networkutils-all-0.2.jar Test 192.168.170.149
Add a func to do packet dump by using pcap4j.
After build the jar, call the main class PacketDump.
java -Dorg.pcap4j.core.pcapLibName=libpcap.so -cp .:networkutils-all-0.2.jar PacketDump "udp"