Class IpUtils

java.lang.Object
host.anzo.commons.utils.IpUtils

public class IpUtils extends Object
  • Constructor Details

    • IpUtils

      public IpUtils()
  • Method Details

    • getExternalIP

      @Nullable public static @Nullable String getExternalIP()
      Returns:
      external IP address, null if can't detect external IP
    • isLocalAddress

      public static boolean isLocalAddress(@NotNull @NotNull InetAddress address)
      Parameters:
      address - address for check
      Returns:
      true if specified address is local, false otherwise
    • getPing

      public static long getPing(@NotNull @NotNull InetAddress address)
      Parameters:
      address - address to ping
      Returns:
      "dirty" (request-response) ping to specified InetAddress
    • getRealIp

      public static String getRealIp(@NotNull @NotNull spark.Request request)
      Parameters:
      request - request object
      Returns:
      real client IP (in case if using reverse-proxify like a CloudFlare)
    • getRealIp

      public static String getRealIp(@NotNull @NotNull org.eclipse.jetty.websocket.api.Session session)
      Parameters:
      session - websocket session
      Returns:
      extracted from websocket session IP address
    • toLong

      public static long toLong(@NotNull @NotNull String ip)
      Parameters:
      ip - IP address
      Returns:
      IP address packed to long
    • fromLong

      @NotNull public static @NotNull String fromLong(long ipLong)
      Parameters:
      ipLong - IP address as packed long value
      Returns:
      unpacked from long IP address