當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。