public abstract class Network
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static java.util.List<java.net.InterfaceAddress> |
allAddresses |
Constructor and Description |
---|
Network() |
Modifier and Type | Method and Description |
---|---|
static boolean |
belongsToSubnet(java.net.Inet4Address address,
java.lang.String subnet)
Checks if a given IPv4 address belongs to a given subnet
|
static java.net.InetAddress |
getInetAddress(java.lang.String subnet) |
static java.net.InetAddress[] |
getInetAddresses()
Get all locally available IPv4 addresses but the loopback address.
|
static boolean |
isLocalAddress(java.net.InetAddress address)
Checks that the given IP address is bound to a local network interface
|
static boolean |
isLocalAddress(java.lang.String address)
Checks that the given IP address is bound to a local network interface
|
static void |
main(java.lang.String[] args)
Prints to standard output the local IP address from
which the provided host IP address or name is reachable.
|
public static java.net.InetAddress getInetAddress(java.lang.String subnet)
subnet
- if not null, this string must specify an IPv4 subnetwork address
in the form b1.b2.b3.b4/maskbits (e.g. 192.168.1.0/24)public static java.net.InetAddress[] getInetAddresses()
public static boolean belongsToSubnet(java.net.Inet4Address address, java.lang.String subnet)
address
- the IPv4 addresssubnet
- the subnet address, specified as b1.b2.b3.b4/maskbits
(e.g. 192.168.1.0/24)public static boolean isLocalAddress(java.lang.String address)
address
- the classical String representation (xxx.xxx.xxx.xxx) of
the IP address to checkpublic static boolean isLocalAddress(java.net.InetAddress address)
address
- the IP address to checkpublic static void main(java.lang.String[] args)
args
- 2 arguments expected:
args[0] the target host IP address or name,
args[1] the timeout in seconds for reachability assessment
of each local address.