public abstract class NetworkUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
NetworkUtils.StackType |
Modifier and Type | Field and Description |
---|---|
static String |
IPv4_SETTING |
static String |
IPv6_SETTING |
static String |
NON_LOOPBACK_ADDRESS |
Modifier and Type | Method and Description |
---|---|
static boolean |
canBindToMcastAddress() |
static Boolean |
defaultReuseAddress() |
static Collection<InetAddress> |
getAllAvailableAddresses() |
static List<NetworkInterface> |
getAllAvailableInterfaces()
Returns all the available interfaces, including first level sub interfaces.
|
static InetAddress |
getFirstAddress(NetworkInterface intf,
NetworkUtils.StackType ipVersion)
Returns the first address with the proper ipVersion on the given interface on the current host.
|
static InetAddress |
getFirstNonLoopbackAddress(NetworkInterface intf,
NetworkUtils.StackType ipVersion)
Returns the first non-loopback address on the given interface on the current host.
|
static InetAddress |
getFirstNonLoopbackAddress(NetworkUtils.StackType ip_version)
Returns the first non-loopback address on any interface on the current host.
|
static NetworkUtils.StackType |
getIpStackType()
Tries to determine the type of IP stack from the available interfaces and their addresses and from the
system properties (java.net.preferIPv4Stack and java.net.preferIPv6Addresses)
|
static InetAddress |
getIPv4Localhost() |
static InetAddress |
getIPv6Localhost() |
static InetAddress |
getLocalAddress() |
static InetAddress |
getLocalhost(NetworkUtils.StackType ip_version) |
static String |
getLocalHostAddress(String defaultHostAddress) |
static String |
getLocalHostName(String defaultHostName) |
static boolean |
interfaceHasIPAddresses(NetworkInterface intf,
NetworkUtils.StackType ipVersion)
A function to check if an interface supports an IP version (i.e has addresses
defined for that IP version).
|
static boolean |
isIPv4() |
static boolean |
isStackAvailable(boolean ipv4) |
public static final String IPv4_SETTING
public static final String IPv6_SETTING
public static final String NON_LOOPBACK_ADDRESS
public static Boolean defaultReuseAddress()
public static boolean isIPv4()
public static InetAddress getIPv4Localhost() throws UnknownHostException
UnknownHostException
public static InetAddress getIPv6Localhost() throws UnknownHostException
UnknownHostException
public static InetAddress getLocalAddress()
public static InetAddress getLocalhost(NetworkUtils.StackType ip_version) throws UnknownHostException
UnknownHostException
public static boolean canBindToMcastAddress()
public static InetAddress getFirstNonLoopbackAddress(NetworkUtils.StackType ip_version) throws SocketException
ip_version
- Constraint on IP version of address to be returned, 4 or 6SocketException
public static InetAddress getFirstNonLoopbackAddress(NetworkInterface intf, NetworkUtils.StackType ipVersion) throws SocketException
intf
- the interface to be checkedipVersion
- Constraint on IP version of address to be returned, 4 or 6SocketException
public static InetAddress getFirstAddress(NetworkInterface intf, NetworkUtils.StackType ipVersion) throws SocketException
intf
- the interface to be checkedipVersion
- Constraint on IP version of address to be returned, 4 or 6SocketException
public static boolean interfaceHasIPAddresses(NetworkInterface intf, NetworkUtils.StackType ipVersion) throws SocketException, UnknownHostException
intf
- SocketException
UnknownHostException
public static NetworkUtils.StackType getIpStackType()
public static boolean isStackAvailable(boolean ipv4)
public static List<NetworkInterface> getAllAvailableInterfaces() throws SocketException
SocketException
public static Collection<InetAddress> getAllAvailableAddresses()
Copyright © 2009–2015. All rights reserved.