• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java PcapNetworkInterface类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.pcap4j.core.PcapNetworkInterface的典型用法代码示例。如果您正苦于以下问题:Java PcapNetworkInterface类的具体用法?Java PcapNetworkInterface怎么用?Java PcapNetworkInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PcapNetworkInterface类属于org.pcap4j.core包,在下文中一共展示了PcapNetworkInterface类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: _selectSuitableNetworkInterface

import org.pcap4j.core.PcapNetworkInterface; //导入依赖的package包/类
/**
 * select a most suitable network interface according to the address
 *
 * @param address
 * @return
 */
private SelectedInterface _selectSuitableNetworkInterface(InetAddress address) {
    int similiarBytes = Integer.MIN_VALUE;
    SelectedInterface selectedInterface = new SelectedInterface();

    byte[] inputIpInBytes = address.getAddress();
    for (PcapNetworkInterface currentInterface : _localPcapNetworkInterfaces) {
        List<PcapAddress> addresses = currentInterface.getAddresses();
        if (addresses != null) {
            for (PcapAddress ipAddress : addresses) {
                // make sure the address should be same type, all ipv4 or all ipv6
                if (!_isSameTypeAddress(address, ipAddress.getAddress())) {
                    continue;
                }
                byte[] ipInBytes = ipAddress.getAddress().getAddress();
                int currentSimiliarBytes = _similarBytes(inputIpInBytes, ipInBytes);
                if (currentSimiliarBytes > similiarBytes) {
                    selectedInterface._selectedNetworkInterface = currentInterface;
                    selectedInterface._selectedIpAddress = ipAddress.getAddress();
                    similiarBytes = currentSimiliarBytes;
                }
            }
        }
    }
    return selectedInterface;
}
 
开发者ID:gaoxingliang,项目名称:mac-address-detector-java,代码行数:32,代码来源:MacAddressHelper.java


示例2: show

import org.pcap4j.core.PcapNetworkInterface; //导入依赖的package包/类
void show(Config config) {
    try {
        List<PcapNetworkInterface> devices = Pcaps.findAllDevs();
        List<String> names = devices.stream().map(PcapNetworkInterface::getName).collect(Collectors.toList());
        ChoiceDialog<String> dialog = new ChoiceDialog<>(names.get(0), names);
        dialog.initModality(Modality.WINDOW_MODAL);
        dialog.setResizable(false);
        dialog.setHeaderText("Choose a network interface:");
        Optional<String> result = dialog.showAndWait();
        if (result.isPresent()) {
            config.setDevice(dialog.getSelectedItem());
            MainWindow app = new MainWindow("Knitcap");
            app.start(config);
        }
    } catch (PcapNativeException e) {
        e.printStackTrace();
    }
}
 
开发者ID:wakamesoba98,项目名称:knitcap,代码行数:19,代码来源:DeviceDialog.java


示例3: getMode

import org.pcap4j.core.PcapNetworkInterface; //导入依赖的package包/类
PromiscuousMode getMode(PcapNetworkInterface pi){
	PromiscuousMode mode=null;
	String string=(pi.getDescription()+":"+pi.getName()).toLowerCase();
	if(string.contains("wireless")){
		mode=PromiscuousMode.NONPROMISCUOUS;
	}else {
		mode=PromiscuousMode.PROMISCUOUS;
	}
	return mode;
}
 
开发者ID:jonasxiao,项目名称:FinalSpeed,代码行数:11,代码来源:CapEnv.java


示例4: toInterfaceAddresses

import org.pcap4j.core.PcapNetworkInterface; //导入依赖的package包/类
@Nonnull
private static InterfaceAddress[] toInterfaceAddresses(@Nonnull PcapNetworkInterface iface) {
    Preconditions.checkNotNull(iface, "PcapNetworkInterface was null.");
    List<InterfaceAddress> out = new ArrayList<InterfaceAddress>();
    for (PcapAddress address : iface.getAddresses())
        out.add(toInterfaceAddress(address));
    return out.toArray(new InterfaceAddress[out.size()]);
}
 
开发者ID:shevek,项目名称:dhcp4j,代码行数:9,代码来源:DhcpServer.java


示例5: getDevices

import org.pcap4j.core.PcapNetworkInterface; //导入依赖的package包/类
public Map<String, String> getDevices() {
  Map<String, String> map = new TreeMap<String, String>();
  int id = 0;
  for (PcapNetworkInterface dev: DEVICE_LIST) {
    StringBuilder sb = new StringBuilder(100);
    id++;
    sb.append(id).append(":").append(dev.getName());
    map.put(sb.toString(), sb.toString());
  }

  return map;
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:13,代码来源:RealNetworkInterfaceConfigurationAction.java


示例6: packetInit

import org.pcap4j.core.PcapNetworkInterface; //导入依赖的package包/类
/**
 * ��Ʈ��ũ ��Ŷ �ʱ�ȭ
 * 
 * @return PcapHandle
 */
public PcapHandle packetInit() {

	PcapHandle handle = null;
	String connIP = null;
	String reg = "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$";

	try {
		
		// ���� IP �ּ�
		InetAddress local = InetAddress.getLocalHost();
		String localP = local.getHostAddress();
		
		List<String> list = new ArrayList<String>();
		List<String> ip_list = getLocalServerIp();
		for(int i = 0; i < ip_list.size(); i++) {
			if(ip_list.get(i).matches(reg)) {
				System.out.println(ip_list.get(i));
				list.add(ip_list.get(i));
			}
		}
		
		// �ӽ��� ���� �����ǰ� 1���̻��϶�.
		if(list.size() > 1) {
			for(int i = 0; i < list.size(); i++) {
				if(!list.get(i).equals(localP)) {
					// ���� �����ǰ� �ƴѰ�,
					connIP = list.get(i);
				}
			}
		} else {
			connIP = localP;
		}
		
		System.out.println("�������� ������: " + connIP);
		
		// �����ϰ��� �ϴ� �������̽� ����
		InetAddress addr = InetAddress.getByName(connIP);
		PcapNetworkInterface nif = Pcaps.getDevByAddress(addr);
		
		// ��Ŷ��� �ڵ鷯 ����
		PromiscuousMode mode = PromiscuousMode.PROMISCUOUS;
		handle = nif.openLive(SNAPLEN, mode, TIME_OUT);

	} catch (Exception e) {
		e.printStackTrace();
	}

	return handle;

}
 
开发者ID:kimyearho,项目名称:FF14_ScraperChat,代码行数:56,代码来源:PacketInstance.java


示例7: getLocalInterfaces

import org.pcap4j.core.PcapNetworkInterface; //导入依赖的package包/类
public List<PcapNetworkInterface> getLocalInterfaces() {
    if (!_initted) {
        throw new IllegalStateException("Fail to init component", _initError);
    }
    return _localPcapNetworkInterfaces;
}
 
开发者ID:gaoxingliang,项目名称:mac-address-detector-java,代码行数:7,代码来源:MacAddressHelper.java


示例8: main

import org.pcap4j.core.PcapNetworkInterface; //导入依赖的package包/类
/**
 * @param args the remote device ip lists split by comma
 */
public static void main(String[] args) {

    // check libpcap file really exists
    String libpcapKeyName = "org.pcap4j.core.pcapLibName";
    String libpcapSet = System.getProperty(libpcapKeyName);
    if (libpcapSet == null || libpcapSet.isEmpty()) {
        System.out.println(String.format("no libpcap property set, try with -D%s=YourLibPcapFile", libpcapKeyName));
        return;
    }
    File libpcapFile = new File(libpcapSet);
    if (!(libpcapFile.exists() && libpcapFile.isFile())) {
        System.out.println("libpcap file not exists " + libpcapFile.getAbsolutePath());
        return;
    }
    System.out.println("Use libpcap file - " + libpcapFile.getAbsolutePath());
    System.out.println();
    System.out.println("Version - " + Pcaps.libVersion());
    // list all interfaces
    List<PcapNetworkInterface> localInterfaces = MacAddressHelper.getInstance().getLocalInterfaces();
    System.out.println("List local interfaces");
    for (PcapNetworkInterface localIntf : localInterfaces) {
        System.out.println("\t" + localIntf);
    }

    if (args == null || args.length == 0) {
        System.out.println("No remote device ips provided. try with arguments IP1,IP2 ....");
        return;
    }
    for (String ip : args) {
        System.out.println("Start find mac for ip - " + ip);
        try {
            MacAddress mac = MacAddressHelper.getInstance().getMacAddress(InetAddress.getByName(ip));
            System.out.println("The mac is - " + mac);
        }
        catch (UnknownHostException e) {
            System.out.println("Unknown host " + ip);
            e.printStackTrace();
        }
    }

    MacAddressHelper.getInstance().shutdown();

}
 
开发者ID:gaoxingliang,项目名称:mac-address-detector-java,代码行数:47,代码来源:MacAddressHelper.java


示例9: getLocalAddr

import org.pcap4j.core.PcapNetworkInterface; //导入依赖的package包/类
public static void getLocalAddr() throws InterruptedException, PcapNativeException, UnknownHostException, SocketException,
		ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
	if (Settings.getDouble("autoload", 0) == 1) {
		addr = InetAddress.getByName(Settings.get("addr", ""));
		return;
	}

	UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
	final JFrame frame = new JFrame("Network Device");
	frame.setFocusableWindowState(true);

	final JLabel ipLab = new JLabel("Select LAN IP obtained from Network Settings:", JLabel.LEFT);
	final JComboBox<String> lanIP = new JComboBox<String>();
	final JLabel lanLabel = new JLabel("If your device IP isn't in the dropdown, provide it below.");
	final JTextField lanText = new JTextField(Settings.get("addr", ""));

	ArrayList<InetAddress> inets = new ArrayList<InetAddress>();

	for (PcapNetworkInterface i : Pcaps.findAllDevs()) {
		for (PcapAddress x : i.getAddresses()) {
			InetAddress xAddr = x.getAddress();
			if (xAddr != null && x.getNetmask() != null && !xAddr.toString().equals("/0.0.0.0")) {
				NetworkInterface inf = NetworkInterface.getByInetAddress(x.getAddress());
				if (inf != null && inf.isUp() && !inf.isVirtual()) {
					inets.add(xAddr);
					lanIP.addItem((lanIP.getItemCount() + 1) + " - " + inf.getDisplayName() + " ::: " + xAddr.getHostAddress());
					System.out.println("Found: " + lanIP.getItemCount() + " - " + inf.getDisplayName() + " ::: " + xAddr.getHostAddress());
				}
			}
		}
	}

	if (lanIP.getItemCount() == 0) {
		JOptionPane.showMessageDialog(null, "Unable to locate devices.\nPlease try running the program in Admin Mode.\nIf this does not work, you may need to reboot your computer.",
				"Error", JOptionPane.ERROR_MESSAGE);
		System.exit(1);
	}
	lanIP.setFocusable(false);
	final JButton start = new JButton("Start");
	start.addActionListener(e -> {
		try {
			if (lanText.getText().length() >= 7 && !lanText.getText().equals("0.0.0.0")) { // 7 is because the minimum field is 0.0.0.0
				addr = InetAddress.getByName(lanText.getText());
				System.out.println("Using IP from textfield: " + lanText.getText());
			} else {
				addr = inets.get(lanIP.getSelectedIndex());
				System.out.println("Using device from dropdown: " + lanIP.getSelectedItem());
			}
			Settings.set("addr", addr.getHostAddress().replaceAll("/", ""));
			frame.setVisible(false);
			frame.dispose();
		} catch (UnknownHostException e1) {
			e1.printStackTrace();
		}
	});

	frame.setLayout(new GridLayout(5, 1));
	frame.add(ipLab);
	frame.add(lanIP);
	frame.add(lanLabel);
	frame.add(lanText);
	frame.add(start);
	frame.setAlwaysOnTop(true);
	frame.pack();
	frame.setLocationRelativeTo(null);
	frame.setVisible(true);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	while (frame.isVisible())
		Thread.sleep(10);
}
 
开发者ID:PsiLupan,项目名称:MakeLobbiesGreatAgain,代码行数:72,代码来源:Boot.java


示例10: apply

import org.pcap4j.core.PcapNetworkInterface; //导入依赖的package包/类
@Override
public PcapNetworkInterfaceWrapper apply(PcapNetworkInterface pcapNetworkInterface) {
    return new PcapNetworkInterfaceWrapper(pcapNetworkInterface);
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:5,代码来源:PcapNetworkInterfaceWrapper.java


示例11: PcapNetworkInterfaceWrapper

import org.pcap4j.core.PcapNetworkInterface; //导入依赖的package包/类
private PcapNetworkInterfaceWrapper(PcapNetworkInterface pcapNetworkInterface) {
    if (pcapNetworkInterface == null) {
        throw new IllegalArgumentException("Don't pass null.");
    }
    this.pcapNetworkInterface = pcapNetworkInterface;
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:7,代码来源:PcapNetworkInterfaceWrapper.java


示例12: getDeviceList

import org.pcap4j.core.PcapNetworkInterface; //导入依赖的package包/类
public static List<PcapNetworkInterface> getDeviceList() {
  return DEVICE_LIST;
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:4,代码来源:RealNetworkInterfaceConfigurationAction.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java WXImage类代码示例发布时间:2022-05-22
下一篇:
Java XSetLiteral类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap