当前位置: 首页>>代码示例>>Java>>正文


Java Pcap.findAllDevs方法代码示例

本文整理汇总了Java中org.jnetpcap.Pcap.findAllDevs方法的典型用法代码示例。如果您正苦于以下问题:Java Pcap.findAllDevs方法的具体用法?Java Pcap.findAllDevs怎么用?Java Pcap.findAllDevs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jnetpcap.Pcap的用法示例。


在下文中一共展示了Pcap.findAllDevs方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import org.jnetpcap.Pcap; //导入方法依赖的package包/类
/**
 * Initialize service
 *
 * @throws IOException
 * @throws RouteException
 */
@Override
public void init(final ServiceFactory services) throws Exception {
	super.init(services);
	if (Env.INSTANCE.getOs() != OS.mac) {
		services.updateStartup("init.sniffer.network", true);
		try {
			final StringBuilder sb = new StringBuilder();
			final int r = Pcap.findAllDevs(_devices, sb);
			if (r == Pcap.NOT_OK || _devices.isEmpty()) {
				throw new IOException(sb.toString());
			}
			for (final PcapIf net : new ArrayList<>(_devices)) {
				if (net.getAddresses().isEmpty()) {
					_devices.remove(net);
				} else {
					_gatewayMac.put(net, net.getHardwareAddress());
				}
			}
		} catch (final Throwable e) {
			LOGGER.warn("Cannot find a suitable network device for tracing.", e);
		}
	}
}
 
开发者ID:leolewis,项目名称:openvisualtraceroute,代码行数:30,代码来源:JNetCapNetworkService.java

示例2: openLive

import org.jnetpcap.Pcap; //导入方法依赖的package包/类
/**
 * Open live.
 * 
 * @param count
 *          the count
 * @param handler
 *          the handler
 */
public static void openLive(long count, JPacketHandler<Pcap> handler) {
	StringBuilder errbuf = new StringBuilder();
	List<PcapIf> alldevs = new ArrayList<PcapIf>();

	if (Pcap.findAllDevs(alldevs, errbuf) != Pcap.OK) {
		throw new IllegalStateException(errbuf.toString());
	}

	Pcap pcap =
			Pcap.openLive(alldevs.get(0).getName(),
					Pcap.DEFAULT_SNAPLEN,
					Pcap.DEFAULT_PROMISC,
					Pcap.DEFAULT_TIMEOUT,
					errbuf);
	if (pcap == null) {
		throw new IllegalArgumentException(errbuf.toString());
	}

	pcap.loop((int) count, handler, pcap);
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:29,代码来源:TestUtils.java

示例3: getNetworkInterfaces

import org.jnetpcap.Pcap; //导入方法依赖的package包/类
/**
     * Lists all enabled network interfaces on the system.
     */
    public static List<PcapIf> getNetworkInterfaces() {
        List<PcapIf> devices = new ArrayList<>();
        StringBuilder errorBuilder = new StringBuilder();
        if (Pcap.findAllDevs(devices, errorBuilder) == -1) {
            HCapUtils.logger.severe("Unable to list interfaces! " + errorBuilder.toString());
            return devices;
        }
        if (!devices.isEmpty()) {
            HCapUtils.logger.info("Detected " + devices.size() + " network interfaces.");
        } else {
            HCapUtils.logger.info("No network interfaces detected.");
        }
        //  not needed - see jnetpecap docs
//            Pcap.freeAllDevs(deviceNames, errorBuilder);
        return devices;
    }
 
开发者ID:vincentzhang96,项目名称:HearthCaptureLib,代码行数:20,代码来源:NetInterfaces.java

示例4: listDevices

import org.jnetpcap.Pcap; //导入方法依赖的package包/类
public static String listDevices() {
    String ret = "";
	NativeLibraryLoader.loadNativeLibs();
    List<PcapIf> devices = new ArrayList<PcapIf>();
    StringBuilder err = new StringBuilder();

    if (Pcap.findAllDevs(devices, err) != Pcap.OK || devices.isEmpty()) {
    	log.error("Failed to find network devices");
        throw new RuntimeException("Failed to find network devices!");
    }

    for (PcapIf dev : devices) {
        ret += dev.getName() + "\n";
    }

    return ret;
}
 
开发者ID:fg-netzwerksicherheit,项目名称:jnetpcapfacade,代码行数:18,代码来源:PcapHelper.java

示例5: openAnyDevice

import org.jnetpcap.Pcap; //导入方法依赖的package包/类
@Test
public void openAnyDevice() {
    List<PcapIf> devices = new ArrayList<PcapIf>();
    StringBuilder err = new StringBuilder();

    if (Pcap.findAllDevs(devices, err) != Pcap.OK || devices.isEmpty()) {
        throw new RuntimeException("Failed to find network devices!");
    }

    Pcap pcap = null;
    for (PcapIf dev : devices) {
        if (dev.getName().equalsIgnoreCase(Constants.ANY_DEVICE)) {
            pcap = Pcap.create(Constants.ANY_DEVICE, err);
        }
    }

    if (pcap == null) {
        throw new RuntimeException("Failed to open \""
                + Constants.ANY_DEVICE + "\" device!");
    }
    
    pcap.close();
}
 
开发者ID:fg-netzwerksicherheit,项目名称:jnetpcapfacade,代码行数:24,代码来源:SimplePcapCaptureTests.java

示例6: _testPcapCanSetRfMond

import org.jnetpcap.Pcap; //导入方法依赖的package包/类
public void _testPcapCanSetRfMond() throws SecurityException,
		NoSuchMethodException {
	List<PcapIf> alldevs = new ArrayList<PcapIf>();
	StringBuilder errbuf = new StringBuilder();

	Pcap.findAllDevs(alldevs, errbuf);
	Pcap pcap = Pcap.create(alldevs.get(0).getName(), errbuf);

	if (Pcap.isLoaded("canSetRfmon")) {
		pcap.canSetRfmon();
	}

	pcap.close();

}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:16,代码来源:TestLibrary.java

示例7: getAllPcapDevices

import org.jnetpcap.Pcap; //导入方法依赖的package包/类
/**
 * This function returns a list of all available <code>PcapIf</code>s.
 *
 * @param rescan
 * @return
 * @throws PcapException
 */
public static List<PcapIf> getAllPcapDevices(boolean rescan) throws PcapException {
    if (rescan || allPcapDevices == null) {
        allPcapDevices = new ArrayList<PcapIf>();

        StringBuilder errbuf = new StringBuilder();
        int r = Pcap.findAllDevs(allPcapDevices, errbuf);
        if (r != Pcap.OK) {
            throw new PcapException("Can't read list of devices: " + errbuf.toString());
        }
    }

    return Collections.unmodifiableList(allPcapDevices);
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:21,代码来源:PcapUtils.java

示例8: listNetworkInterfaces

import org.jnetpcap.Pcap; //导入方法依赖的package包/类
private static List<PcapIf> listNetworkInterfaces() throws Exception {
    final StringBuilder errbuf = new StringBuilder();
    List<PcapIf> result = new ArrayList<>(); // Will be filled with NICs
    int r = Pcap.findAllDevs(result, errbuf);
    if (r == Pcap.ERROR || result.isEmpty())
        throw new Exception ("Can't read list of devices, error is :" + errbuf.toString());

    return result;
}
 
开发者ID:andymalakov,项目名称:libpcap-latency-meter,代码行数:10,代码来源:LiveCaptureProcessor.java

示例9: createAndActivatePcap

import org.jnetpcap.Pcap; //导入方法依赖的package包/类
public static Pcap createAndActivatePcap(String device) {
	NativeLibraryLoader.loadNativeLibs();
    Pcap pcap = null;

    List<PcapIf> devices = new ArrayList<PcapIf>();
    StringBuilder err = new StringBuilder();

    if (Pcap.findAllDevs(devices, err) != Pcap.OK || devices.isEmpty()) {
    	log.error("Failed to find network devices");
        throw new RuntimeException("Failed to find network devices!");
    }

    for (PcapIf dev : devices) {
        if (dev.getName().equalsIgnoreCase(device)) {
            pcap = Pcap.create(device, err);
            break;
        }
    }

    if (pcap == null && devices.size() < 1) {
    	log.error("Failed to open device: " + device);
        throw new RuntimeException("Failed to open \"" + device + "\" device!");
    } else if (pcap == null) {
    	log.error("Failed to get requested device: " + device);
        device = devices.get(0).getName();
        log.error("Using first device found: " + device);
        pcap = Pcap.create(device, err);
    }

    pcap.setSnaplen(Constants.SNAPLEN);
    pcap.setPromisc(Constants.FLAGS);
    pcap.setBufferSize(Constants.BUFFER_SIZE);

    if (pcap.activate() != 0) {
    	log.error("Failed to activate device: " + device + " -> " + pcap.getErr());
        throw new RuntimeException("Failed to activate \"" + device + "\" device!\n" + "Pcap error follows:\n" + pcap.getErr());
    }

    return pcap;
}
 
开发者ID:fg-netzwerksicherheit,项目名称:jnetpcapfacade,代码行数:41,代码来源:PcapHelper.java

示例10: getDeviceList

import org.jnetpcap.Pcap; //导入方法依赖的package包/类
@Test
public void getDeviceList() {
    List<PcapIf> devices = new ArrayList<PcapIf>();
    StringBuilder err = new StringBuilder();

    if (Pcap.findAllDevs(devices, err) != Pcap.OK || devices.isEmpty()) {
        throw new RuntimeException("Failed to find network devices!");
    }

    for (PcapIf dev : devices) {
        System.out.println(dev.getName() + " " + dev.getDescription());
    }
}
 
开发者ID:fg-netzwerksicherheit,项目名称:jnetpcapfacade,代码行数:14,代码来源:SimplePcapCaptureTests.java

示例11: generateListOfDevicesWithIPs

import org.jnetpcap.Pcap; //导入方法依赖的package包/类
private void generateListOfDevicesWithIPs()
{
	List<PcapIf> deviceList = new ArrayList<>();
	StringBuilder errbuf = new StringBuilder();

	int r = Pcap.findAllDevs(deviceList, errbuf);

	if (r == Pcap.ERROR || deviceList.isEmpty())
	{
		logger.log(Level.SEVERE, "Can't read list of devices, error is " + errbuf.toString());
		return;
	}
	
	for (PcapIf device : deviceList)
	{
		String description = (device.getDescription() != null) ? device.getDescription() : "No description available";
		String ip = null;
		for (PcapAddr pcapAddr : device.getAddresses())
		{
			String temp = pcapAddr.getAddr().toString();

			if (temp.contains(Ipv4Prefix))
			{
				ip = temp.replace(Ipv4Prefix, "");
				break;
			}
		}

		if (ip == null || ip.equals("[0.0.0.0]"))
			continue;

		byte[] hardwareAddress;

		try
		{
			hardwareAddress = device.getHardwareAddress();
		}
		catch (IOException ioe)
		{
			hardwareAddress = new byte[8];
		}

		NICInfo nicInfo = new NICInfo(ip, hardwareAddress, description);
		ipAndDescList.add(nicInfo);
		nicInfoToPcapIf.put(nicInfo, device);
	}
}
 
开发者ID:ck3ck3,项目名称:WhoWhatWhere,代码行数:48,代码来源:NetworkSniffer.java

示例12: activateAnyDevice

import org.jnetpcap.Pcap; //导入方法依赖的package包/类
@Test
public void activateAnyDevice() {
    List<PcapIf> devices = new ArrayList<PcapIf>();
    StringBuilder err = new StringBuilder();

    if (Pcap.findAllDevs(devices, err) != Pcap.OK || devices.isEmpty()) {
        throw new RuntimeException("Failed to find network devices!");
    }

    for (PcapIf dev : devices) {
        if (dev.getName().equalsIgnoreCase(Constants.ANY_DEVICE)) {
            pcap = Pcap.create(Constants.ANY_DEVICE, err);
        }
    }

    if (pcap == null) {
        throw new RuntimeException("Failed to open \""
                + Constants.ANY_DEVICE + "\" device!");
    }

    pcap.setSnaplen(Constants.SNAPLEN);
    pcap.setPromisc(Constants.FLAGS);
    pcap.setBufferSize(Constants.BUFFER_SIZE);

    if (pcap.activate() != 0) {
        throw new RuntimeException("Failed to activate \""
                + Constants.ANY_DEVICE + "\" device!");
    }

    /*
     * The pcap.loop is blocking so we use a thread as timer to stop
     * capturing.
     */
    Thread stopper = new Thread() {
        @Override
        public void run() {
            try {
                sleep(TestConstants.CAPTURE_DELAY);
                pcap.breakloop();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    };
    stopper.start();

    int ret = pcap.loop(Pcap.LOOP_INFINITE,
            new PcapPacketHandler<Object>() {
                @Override
                public void nextPacket(PcapPacket arg0, Object arg1) {
                }
            }, null);

    /*
     * As we break the loop we check the return value if this was correctly
     * done.
     */
    assertEquals(Pcap.ERROR_BREAK, ret);
    pcap.close();
}
 
开发者ID:fg-netzwerksicherheit,项目名称:jnetpcapfacade,代码行数:61,代码来源:SimplePcapCaptureTests.java

示例13: getNics

import org.jnetpcap.Pcap; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
	public List <PcapIf> getNics(){
	List<PcapIf> alldevs = new ArrayList<PcapIf>();
    for(PcapIf p : alldevs ){
    	System.out.println(p.getName());
    }
    int r = Pcap.findAllDevs(alldevs, errbuf);
    if (r == Pcap.NOT_OK || alldevs.isEmpty()) {
    	JOptionPane.showMessageDialog(null, "Not able to read list of devices \n"+ errbuf.toString(), "Error(Devices)", JOptionPane.ERROR_MESSAGE);
    }
    
    return alldevs;
}
 
开发者ID:YassineFadhlaoui,项目名称:ARP-Spoofing,代码行数:14,代码来源:Start_Spoofing.java

示例14: getDeviceList

import org.jnetpcap.Pcap; //导入方法依赖的package包/类
public List<PcapIf> getDeviceList() {
    List<PcapIf> pcapIfs = new ArrayList<>();
    StringBuilder errBuf = new StringBuilder();
    int code = Pcap.findAllDevs(pcapIfs, errBuf);
    if (code != Pcap.OK || pcapIfs.isEmpty()) {
        System.err.println("There is no network interface:" + errBuf);
    }
    return pcapIfs;
}
 
开发者ID:whinc,项目名称:PcapAnalyzer,代码行数:10,代码来源:PcapManager.java


注:本文中的org.jnetpcap.Pcap.findAllDevs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。