【问题标题】:Unable to receive packet using jpcap in WiFi network无法在 WiFi 网络中使用 jpcap 接收数据包
【发布时间】:2015-05-15 19:37:49
【问题描述】:

我想在 WiFi 网络中发送和接收数据包。 使用以下代码

发送数据包。

int id = Integer.parseInt(text_device.getText().trim());
JpcapCaptor jpcap = JpcapCaptor.openDevice(devices[id], 65535, true, 20);
JpcapSender sender = jpcap.getJpcapSenderInstance();
TCPPacket packet = new TCPPacket(210, 210, 0l, 12l, true, true, true, true, true, true, true, true, 1, 2);
packet.setIPv4Parameter(0, true, true, true, 0, true, true, true, 0, 1010101, 100, IPPacket.IPPROTO_TCP, InetAddress.getLocalHost(), InetAddress.getByName(text_ip.getText().trim()));
packet.data = "Sample Data".getBytes();
Date date = new Date();
packet.usec = date.getTime();
packet.sec = date.getTime();
EthernetPacket ether = new EthernetPacket();
ether.src_mac = new byte[]{(byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1};
ether.dst_mac = new byte[]{(byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255, (byte) 255};
ether.frametype = EthernetPacket.ETHERTYPE_IP;
packet.datalink = ether;
sender.sendPacket(packet);

为了接收数据包,我将这段代码写在public void receivePacket(Packet packet)

TCPPacket tcp = (TCPPacket) packet;
String src = tcp.src_ip.getHostAddress();
int src_port = tcp.src_port;
String dst = tcp.dst_ip.getHostAddress();
int dst_port = tcp.dst_port;
String data = new String(tcp.data);
System.out.println("" + data + "");

当我用局域网连接两台机器时它可以工作,但当我用WiFi连接时无法接收数据包。

谁能给我建议,怎么了??

【问题讨论】:

    标签: java networking winpcap jpcap


    【解决方案1】:

    我怀疑答案与 JPCAP FAQ 中的这句话有关:

    问:我可以从 WiFi (802.11) 网络接口捕获数据包吗?

    答案取决于您运行的是什么操作系统以及哪个 您的系统拥有的 WiFi 设备。在 Windows 上,您可能无法 从某些 WiFi 设备捕获数据包。 Linux 或 BSD 可能有更高的 支持使用 WiFi 设备抓包的概率。

    如果您分享您的准确适配器类型和 Windows 版本详细信息,您可能会在 Google discussion group 上为 JPcap 获得更好的成功。

    【讨论】:

    • 你建议我现在应该怎么做..因为我必须使用windows??
    猜你喜欢
    • 2017-02-03
    • 2021-09-15
    • 1970-01-01
    • 2015-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-03
    相关资源
    最近更新 更多