Package io.jans.net

Class InetAddressUtility

java.lang.Object
io.jans.net.InetAddressUtility

public final class InetAddressUtility extends Object
Author:
Yuriy Movchan Date: 05/20/2015
  • Method Details

    • getMACAddressOrRandomUUID

      public static String getMACAddressOrRandomUUID()
      Stable identifier of this JVM's host: the MAC address of the interface bound to the local host address (see getMACAddressOrNull()); failing that, the MAC of the first (by name) non-loopback, non-virtual, up interface that has one; failing that, a random UUID that is stable only for the lifetime of the process. Computed once and cached. Never returns null or an empty string; the result is at most 36 characters.

      The second tier matters on Debian/Ubuntu-style hosts where the host name resolves to 127.0.1.1: NetworkInterface.getByInetAddress(java.net.InetAddress) returns null there, so getMACAddressOrNull() alone yields null even when a real NIC exists.

    • isIpAddress

      public static boolean isIpAddress(String ipAddress)
      Determine if the given string is a valid IPv4 or IPv6 address
    • getMACAddressOrNull

      public static String getMACAddressOrNull()
    • getIpAddress

      public static String getIpAddress(jakarta.servlet.http.HttpServletRequest httpRequest)
      Parameters:
      httpRequest - interface to provide request information for HTTP servlets.
      Returns:
      IP address of client
      See Also: