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


Java InetAddress.getClass方法代码示例

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


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

示例1: getInventoryEndpoints

import java.net.InetAddress; //导入方法依赖的package包/类
public List<String> getInventoryEndpoints() {
  List<String> endpoints = new ArrayList<>(2);
  try {
    Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
    for (NetworkInterface netint : Collections.list(nets)) {
      Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
      for (InetAddress addr : Collections.list(inetAddresses)) {
        if (!addr.isLinkLocalAddress() && addr.getClass() == Inet4Address.class) {
          endpoints.add(
              String.format("http://%s:%d/v1/grapher/inventory", addr.getHostAddress(), port));
        }
      }
    }
  } catch (SocketException e) {
    logger.error("Exception looking up network interfaces", e);
  }
  return endpoints;
}
 
开发者ID:strykeforce,项目名称:thirdcoast,代码行数:19,代码来源:TelemetryController.java

示例2: getLinkLocalAddress

import java.net.InetAddress; //导入方法依赖的package包/类
/**
 * Determines the link-local IPv6 address which is configured on the network interface provided
 * in the properties file.
 * @return The link-local address given as a String
 */
public static Inet6Address getLinkLocalAddress() {
	String networkInterfaceConfig = getPropertyValue("network.interface").toString();
	
	NetworkInterface nif = null;
	
	try {
		if (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) {
			nif = NetworkInterface.getByIndex(Integer.parseInt(networkInterfaceConfig));
		} else {
			nif = NetworkInterface.getByName(networkInterfaceConfig);
		}
		Enumeration<InetAddress> inetAddresses = nif.getInetAddresses();
		
		while (inetAddresses.hasMoreElements()) {
			InetAddress inetAddress = inetAddresses.nextElement();
			
			if (inetAddress.getClass() == Inet6Address.class && inetAddress.isLinkLocalAddress()) {
				return (Inet6Address) inetAddress;
			}
		}
		
		getLogger().fatal("No IPv6 link-local address found on the network interface '" +
				nif.getDisplayName() + "' configured in the properties file");
	} catch (SocketException e) {
		getLogger().fatal("SocketException while trying to get network interface for configured name " +
						  networkInterfaceConfig + "'", e); 
	} catch (NullPointerException | NumberFormatException e2) {
		getLogger().fatal("No network interface for configured network interface index '" + 
						  networkInterfaceConfig + "' found");
	}
	
	return null;
}
 
开发者ID:V2GClarity,项目名称:RISE-V2G,代码行数:39,代码来源:MiscUtils.java


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