使用jNetPcap AP捕获网络数据包

时间:2017-11-15 08:06:15

标签: java

我正在尝试用Java捕获SIP和RTP流量。要开始我使用此代码,但它仍然不适合我。我收到了错误

  

无法读取设备列表,错误是

没有任何其他指示或消息。我无法找到问题的确切位置!

请建议我的解决方案。这是我的代码:

public class Example {
    public static void main(String[] args) {
        List<PcapIf> alldevs = new ArrayList<PcapIf>(); // Will be filled with
                                                        // NICs
        StringBuilder errbuf = new StringBuilder(); // For any error msgs
        int r = Pcap.findAllDevs(alldevs, errbuf);
        if (r == Pcap.NOT_OK || alldevs.isEmpty()) {
            System.err.printf("Can't read list of devices, error is %s",
                    errbuf.toString());
            return;
        }
        System.out.println("Network devices found:");
        int i = 0;
        for (PcapIf device : alldevs) {
            String description = (device.getDescription() != null) ? device
                    .getDescription() : "No description available";
            System.out.printf("#%d: %s [%s]\n", i++, device.getName(),
                    description);
        }
    }
}

0 个答案:

没有答案
相关问题