Package com.microej.kf.util.control.net
Class Subnet
- java.lang.Object
-
- com.microej.kf.util.control.net.Subnet
-
public class Subnet extends java.lang.ObjectSubnet representation with its network address and mask in bits. E.g: For the subnet 28.10.0.0/16, 28.10.0.0 represents the network address and 16 is the mask in bits.
-
-
Constructor Summary
Constructors Constructor Description Subnet(java.net.InetAddress networkAddress, int mask)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object obj)static SubnetfromCidrNotation(java.lang.String cidrSubnet)Creates an instance ofSubnetfrom the given subnet string which is in CIDR notation (e.g: 192.168.1.0/24).intgetMask()Gets the mask of the subnet (in bits).java.net.InetAddressgetNetworkAddress()Gets the network address of the subnet.inthashCode()booleanmatches(java.net.InetAddress ipAddress)Checks if the given ip address matches with the subnet.java.lang.StringtoString()
-
-
-
Method Detail
-
getNetworkAddress
public java.net.InetAddress getNetworkAddress()
Gets the network address of the subnet.- Returns:
- the network address of the subnet.
-
getMask
public int getMask()
Gets the mask of the subnet (in bits).- Returns:
- the mask of the subnet (in bits).
-
matches
public boolean matches(java.net.InetAddress ipAddress)
Checks if the given ip address matches with the subnet.- Parameters:
ipAddress- the ip address.- Returns:
- true on success; false otherwise.
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
fromCidrNotation
public static Subnet fromCidrNotation(java.lang.String cidrSubnet) throws java.net.UnknownHostException
Creates an instance ofSubnetfrom the given subnet string which is in CIDR notation (e.g: 192.168.1.0/24).- Parameters:
cidrSubnet- the subnet in CIDR notation.- Returns:
Subnetinstance from the given CIDR notation.- Throws:
java.net.UnknownHostException- if the subnet IP address cannot be resolved.
-
-