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


Java NetworkInterface.getSubInterfaces方法代码示例

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


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

示例1: getSubinterfaceInetAddrs

import java.net.NetworkInterface; //导入方法依赖的package包/类
/**
 * @param nif network interface to get addresses for
 * @return set containing addresses for each subinterface of nif,
 *    see below for the rationale for using an ordered set
 */
private static LinkedHashSet<InetAddress> getSubinterfaceInetAddrs(
    NetworkInterface nif) {
  LinkedHashSet<InetAddress> addrs = new LinkedHashSet<InetAddress>();
  Enumeration<NetworkInterface> subNifs = nif.getSubInterfaces();
  while (subNifs.hasMoreElements()) {
    NetworkInterface subNif = subNifs.nextElement();
    addrs.addAll(Collections.list(subNif.getInetAddresses()));
  }
  return addrs;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:16,代码来源:DNS.java

示例2: getIPs

import java.net.NetworkInterface; //导入方法依赖的package包/类
/**
 * Return an InetAddress for each interface that matches the
 * given subnet specified using CIDR notation.
 *
 * @param subnet subnet specified using CIDR notation
 * @param returnSubinterfaces
 *            whether to return IPs associated with subinterfaces
 * @throws IllegalArgumentException if subnet is invalid
 */
public static List<InetAddress> getIPs(String subnet,
    boolean returnSubinterfaces) {
  List<InetAddress> addrs = new ArrayList<InetAddress>();
  SubnetInfo subnetInfo = new SubnetUtils(subnet).getInfo();
  Enumeration<NetworkInterface> nifs;

  try {
    nifs = NetworkInterface.getNetworkInterfaces();
  } catch (SocketException e) {
    LOG.error("Unable to get host interfaces", e);
    return addrs;
  }

  while (nifs.hasMoreElements()) {
    NetworkInterface nif = nifs.nextElement();
    // NB: adding addresses even if the nif is not up
    addMatchingAddrs(nif, subnetInfo, addrs);

    if (!returnSubinterfaces) {
      continue;
    }
    Enumeration<NetworkInterface> subNifs = nif.getSubInterfaces();
    while (subNifs.hasMoreElements()) {
      addMatchingAddrs(subNifs.nextElement(), subnetInfo, addrs);
    }
  }
  return addrs;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:38,代码来源:NetUtils.java


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