【问题标题】:Java - Pcap4j only detects host device's adressJava - Pcap4j 只检测主机设备的地址
【发布时间】:2018-05-11 18:52:31
【问题描述】:

我一直在尝试编写一个用于 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

【问题讨论】:

    标签: java networking winpcap jpcap pcap4j


    【解决方案1】:

    你的意思是你想做Remote Capture

    Pcap4J 暂时不支持。

    【讨论】:

    • 不,我试图嗅探我的本地网络。无论如何,谢谢,我找到了解决方法! ;)
    • 愿意分享吗?我也想做同样的事情。谢谢!
    猜你喜欢
    • 2014-03-04
    • 1970-01-01
    • 2011-09-07
    • 1970-01-01
    • 2018-04-15
    • 2011-09-06
    • 1970-01-01
    • 2011-03-23
    • 2016-11-28
    相关资源
    最近更新 更多