本文整理汇总了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;
}
示例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;
}