我一直在尝试编写用于ARP数据包检测的嗅探器。我已经让Pcap4j库运行并检测我的网络,但它只显示当前在地址列表中运行的计算机。有很多不同的设备连接到网络,Wireshark可以检测到它们。我已经检查过,至少主机和另一台机器的检测设置在Windows设置中打开,它们可以在Windows网络中相互识别。
这是非常基本的代码:
package arpsniffer;
import java.io.IOException;
import org.pcap4j.core.PcapNetworkInterface;
import org.pcap4j.util.LinkLayerAddress;
import org.pcap4j.util.NifSelector;
/**
*
* @author Fabio
*/
public class ArpSniffer {
public static void main(String[] args) {
PcapNetworkInterface nif;
try {
nif = new NifSelector().selectNetworkInterface();
for(LinkLayerAddress addr : nif.getLinkLayerAddresses()){
System.out.println(addr.toString());
}
} catch (IOException e) {
}
}
}
这是输出(Pcap4J打开文本对话框让我决定网络设备,我确认它是正确的!)
[main] INFO org.pcap4j.core.NativeMappings - Pcap4J successfully loaded a
native pcap library: WinPcap version 4.1.3 (packet.dll version 4.1.0.2980), based on libpcap version 1.0 branch 1_0_rel0b (20091008)
[main] INFO org.pcap4j.util.PropertiesLoader - [org/pcap4j/pcap4j.properties] Could not get value by org.pcap4j.af.inet, use default value: 2
[main] INFO org.pcap4j.util.PropertiesLoader - [org/pcap4j/pcap4j.properties] Could not get value by org.pcap4j.af.inet6, use default value: 23
[main] INFO org.pcap4j.util.PropertiesLoader - [org/pcap4j/pcap4j.properties] Could not get value by org.pcap4j.af.packet, use default value: 17
[main] INFO org.pcap4j.util.PropertiesLoader - [org/pcap4j/pcap4j.properties] Could not get value by org.pcap4j.af.link, use default value: 18
0
[main] INFO org.pcap4j.core.Pcaps - 1 NIF(s) found.
NIF[0]: \Device\NPF_{/*not showing this stuff here */}
: description: Microsoft
: link layer address: XX:XX:XX:XX:XX:XX //Concealed my adress!
: address: /192.168.192.107
Select a device number to capture packets, or enter 'q' to quit > 0 //This zero here was my personal input
XX:XX:XX:XX:XX:XX