public class InetSubnet
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static InetSubnet |
IPV4_ADDRESS_SPACE
The entire IPv4 address space (including restricted/reserved/private IPs)
This is the subnet 0.0.0.0/0 |
java.net.InetAddress |
network |
int |
prefix |
| Constructor and Description |
|---|
InetSubnet(java.net.InetAddress network,
java.net.InetAddress netmask)
Produces a subnet based on a network IP and a netmask.
|
InetSubnet(java.net.InetAddress network,
int prefix)
Produces a subnet based on a network IP and a prefix
|
InetSubnet(java.net.InterfaceAddress addr) |
InetSubnet(int ip,
int prefix)
Construct a subnet based on
|
InetSubnet(java.lang.String cidr)
Constructs an inet subnet from CIDR representation (
x.x.x.x/prefix) |
InetSubnet(java.lang.String ip,
int prefix) |
| Modifier and Type | Method and Description |
|---|---|
InetSubnet |
canonicalise()
Produces a canonical representation of this subnet; the canonical form has the network ip address properly masked (eg.
|
boolean |
equals(java.lang.Object o) |
java.net.InetAddress |
getBroadcast()
Returns the broadcast address of this subnet
|
java.net.InetAddress |
getHostMax()
Gets the last host in this subnet
|
java.net.InetAddress |
getHostMin()
Gets the first host in this subnet
|
int |
getHosts()
Returns the number of hosts in this subnet
|
java.net.InetAddress |
getIP()
Returns the IP address represented by this subnet; when in its canonical form,
getIP() will return the same as
getNetwork() |
java.net.InetAddress |
getNetmask()
Retrieves the prefix as a netmask (eg.
|
java.net.InetAddress |
getNetwork()
Returns the InetAddress representing the network (fully masked by the prefix); this is the IP address with the last
prefix bits masked to zero |
int |
getPrefix()
Returns the prefix length (0 to 32 for an IPv4 subnet)
The larger the prefix the larger the block if IP addresses represented by this subnet |
java.net.InetAddress |
getWildcardMask()
Retrieves the wildcard mask for the netmask of this subnet
|
int |
hashCode() |
boolean |
isCanonical()
Determines whether this InetSubnet is currently in its canonical form
|
boolean |
isMember(java.net.InetAddress ip)
Determines whether a given IP is a member of this subnet
|
boolean |
isMember(int ip)
Determines whether a given IP, in numeric representation (as returned by
aton()) is a member of this subnetThis is the fastest way to determine subnet membership |
boolean |
isMember(java.lang.String ip)
Determines whether a given IP, given as an IPv4 address in its string representation (x.x.x.x) is a member of this subnet
|
boolean |
member(java.net.InetAddress ip)
Deprecated.
use isMember instead
|
boolean |
member(int ip)
Deprecated.
use isMember instead
|
boolean |
member(java.lang.String ip)
Deprecated.
use isMember instead
|
java.lang.String |
toString()
Emits this subnet in CIDR notation using the prefix (eg.
|
public static final InetSubnet IPV4_ADDRESS_SPACE
public final java.net.InetAddress network
public final int prefix
public InetSubnet(java.net.InterfaceAddress addr)
public InetSubnet(java.lang.String cidr)
x.x.x.x/prefix)tostring - public InetSubnet(java.lang.String ip,
int prefix)
ip - prefix - java.lang.IllegalArgumentException - if the IP address cannot be parsedpublic InetSubnet(int ip,
int prefix)
ip - prefix - public InetSubnet(java.net.InetAddress network,
int prefix)
network - prefix - public InetSubnet(java.net.InetAddress network,
java.net.InetAddress netmask)
network - netmask - public java.lang.String toString()
toString in class java.lang.ObjectObject.toString()public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic java.net.InetAddress getIP()
getIP() will return the same as
getNetwork()public java.net.InetAddress getNetwork()
prefix bits masked to zeropublic int getPrefix()
public java.net.InetAddress getNetmask()
public InetSubnet canonicalise()
10.0.0.3/31 and 10.0.0.2/31 both canonicalise to 10.0.0.2/31)public boolean isCanonical()
public boolean isMember(int ip)
aton()) is a member of this subnetip - public boolean isMember(java.lang.String ip)
ip - java.lang.IllegalArgumentException - if the IP cannot be parsedpublic boolean isMember(java.net.InetAddress ip)
ip - @Deprecated public boolean member(int ip)
ip - @Deprecated public boolean member(java.lang.String ip)
ip - @Deprecated public boolean member(java.net.InetAddress ip)
ip - public int getHosts()
public java.net.InetAddress getHostMin()
public java.net.InetAddress getHostMax()
public java.net.InetAddress getBroadcast()
public java.net.InetAddress getWildcardMask()
Copyright © 2014. All Rights Reserved.