inet.ipaddr

Class HostName

  • java.lang.Object
    • inet.ipaddr.HostName
  • All Implemented Interfaces:
    HostIdentifierString, java.io.Serializable, java.lang.Comparable<HostName>


    public class HostName
    extends java.lang.Object
    implements HostIdentifierString, java.lang.Comparable<HostName>
    An internet host name. Can be a fully qualified domain name, a simple host name, or an ip address string.

    Supported formats

    You can use all host or address formats supported by nmap and all address formats supported by IPAddressString. All manners of domain names are supported. You can add a prefix length to denote the subnet of the resolved address.

    Validation is done separately from DNS resolution to avoid unnecessary lookups.

    See rfc 3513, 2181, 952, 1035, 1034, 1123, 5890 or the list of rfcs for IPAddress. For IPv6 addresses in host, see rfc 2732 specifying [] notation and 3986 and 4038 (combining IPv6 [] with prefix or zone) and SMTP rfc 2821 for alternative uses of [] for both IPv4 and IPv6

    See Also:
    Serialized Form
    Core
    • Constructor Detail

      • HostName

        public HostName(java.net.InetAddress inetAddr)
      • HostName

        public HostName(java.lang.String host)
    • Method Detail

      • isValid

        public boolean isValid()
      • resolvesToSelf

        public boolean resolvesToSelf()
      • isSelf

        public boolean isSelf()
      • isLocalHost

        public boolean isLocalHost()
      • isLoopback

        public boolean isLoopback()
      • toInetAddress

        public java.net.InetAddress toInetAddress()
                                           throws HostNameException,
                                                  java.net.UnknownHostException
        Throws:
        HostNameException
        java.net.UnknownHostException
      • toNormalizedString

        public java.lang.String toNormalizedString()
        Description copied from interface: HostIdentifierString
        provides a normalized String representation for the host identified by this HostIdentifierString instance
        Specified by:
        toNormalizedString in interface HostIdentifierString
        Returns:
        the normalized string
      • equals

        public boolean equals(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

        public java.lang.String[] getNormalizedLabels()
      • getHost

        public java.lang.String getHost()
        Returns the host string normalized but without port, prefix or mask. If an address, returns the address string normalized, but without port, prefix, mask, or brackets for IPv6. To get a normalized string encompassing all details, use toNormalizedString() If not a valid host, returns null
        Returns:
      • matches

        public boolean matches(HostName host)
      • compareTo

        public int compareTo(HostName other)
        Specified by:
        compareTo in interface java.lang.Comparable<HostName>
      • isAddress

        public boolean isAddress()
      • isAddressString

        public boolean isAddressString()
      • isAllAddresses

        public boolean isAllAddresses()
        Returns:
        whether the address represents the set all all valid IP addresses (as opposed to an empty string, a specific address, a prefix length, or an invalid format).
      • isPrefixOnly

        public boolean isPrefixOnly()
        Returns:
        whether the address represents a valid IP address network prefix (as opposed to an empty string, an address with or without a prefix, or an invalid format).
      • isEmpty

        public boolean isEmpty()
        Returns true if the address is empty (zero-length).
        Returns:
      • getPort

        public java.lang.Integer getPort()
        If a port was supplied, returns the port, otherwise returns null
        Returns:
      • getAddressStringException

        public AddressStringException getAddressStringException()
        Returns the exception thrown for invalid ipv6 literal or invalid reverse DNS hosts. This method will return non-null when this host is valid, so no HostException is thrown, but a secondary address within the host is not valid.
        Returns:
      • isUNCIPv6Literal

        public boolean isUNCIPv6Literal()
      • isReverseDNS

        public boolean isReverseDNS()
      • asAddressString

        public IPAddressString asAddressString()
        If this represents an ip address or represents a valid IPAddressString, returns the corresponding address string. Otherwise, returns null. Call toResolvedAddress or resolve to get the resolved address.
        Returns:
      • asAddress

        public IPAddress asAddress()
        If this represents an ip address, returns that address. Otherwise, returns null. Call toResolvedAddress or resolve to get the resolved address, which is different. In cases such as IPv6 literals and reverse DNS hosts, you can check the relevant methods isIpv6Literal or isReverseDNS, in which case this method should return the associated address. If this method returns null then an exception occurred when producing the associated address, and that exception is available from getAddressStringException.
        Returns:
      • toAddress

        public IPAddress toAddress()
                            throws java.net.UnknownHostException,
                                   HostNameException
        If this represents an ip address, returns that address. If this represents a host, returns the resolved ip address of that host. Otherwise, returns null, but only for strings that are considered valid address strings but cannot be converted to address objects. This method will throw exceptions for invalid formats and failures to resolve the address. The equivalent method getAddress() will simply return null rather than throw those exceptions. If you wish to get the represented address and avoid DNS resolution, use asAddress() or asAddressString()
        Specified by:
        toAddress in interface HostIdentifierString
        Returns:
        Throws:
        java.net.UnknownHostException
        HostNameException
      • getAddress

        public IPAddress getAddress()
        If this represents an ip address, returns that address. If this represents a host, returns the resolved ip address of that host. Otherwise, returns null. If you wish to get the represented address and avoid DNS resolution, use asAddress() or asAddressString()
        Specified by:
        getAddress in interface HostIdentifierString
        Returns:
      • toString

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