inet.ipaddr

Class HostName

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


    public class HostName
    extends java.lang.Object
    implements java.lang.Comparable<HostName>, java.io.Serializable
    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 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()
        provides a unique normalized String representation for the host identified by this HostIdentifierString instance
        Returns:
        the normalized string
      • toString

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

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

        public boolean matches(HostName host)
      • hashCode

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

        public java.lang.String[] getNormalizedLabels()
      • 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:
      • toURLString

        public java.lang.String toURLString()
        If this represents an address that was not bracketed as a host, then it returns the bracketed address as a host. This is the standard for IPv6 in URLs. Otherwise, it returns the original string.
      • 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.
        Returns:
      • asAddress

        public IPAddress asAddress(IPAddress.IPVersion version)
        If this represents an ip address, returns that address. Otherwise, returns null. Call toResolvedAddress or resolve to get the resolved address, which is different.
        Returns:
      • resolve

        public IPAddress resolve()
        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.
        Returns: