Class Subnet


  • public class Subnet
    extends java.lang.Object
    Subnet 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
      boolean equals​(java.lang.Object obj)  
      static Subnet fromCidrNotation​(java.lang.String cidrSubnet)
      Creates an instance of Subnet from the given subnet string which is in CIDR notation (e.g: 192.168.1.0/24).
      int getMask()
      Gets the mask of the subnet (in bits).
      java.net.InetAddress getNetworkAddress()
      Gets the network address of the subnet.
      int hashCode()  
      boolean matches​(java.net.InetAddress ipAddress)
      Checks if the given ip address matches with the subnet.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Subnet

        public Subnet​(java.net.InetAddress networkAddress,
                      int mask)
        Parameters:
        networkAddress - the network address of the subnet.
        mask - the mask of the subnet (in bits).
    • 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:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • fromCidrNotation

        public static Subnet fromCidrNotation​(java.lang.String cidrSubnet)
                                       throws java.net.UnknownHostException
        Creates an instance of Subnet from the given subnet string which is in CIDR notation (e.g: 192.168.1.0/24).
        Parameters:
        cidrSubnet - the subnet in CIDR notation.
        Returns:
        Subnet instance from the given CIDR notation.
        Throws:
        java.net.UnknownHostException - if the subnet IP address cannot be resolved.