Class PublicIp

java.lang.Object
dev.demeng.sentinel.client.util.PublicIp

public final class PublicIp extends Object
Resolves the public IP address of the current machine by querying an external service.

This is useful as a workaround when the Sentinel server sits behind a reverse proxy that does not forward the real client IP (e.g. missing X-Forwarded-For headers). The resolved address can be passed to ValidationRequest.Builder.ip(String) so that Sentinel sees the correct IP regardless of proxy configuration.


 ValidationRequest request = ValidationRequest.builder()
     .product("my-product")
     .ip(PublicIp.resolve())
     .build();
 
  • Method Details

    • resolve

      public static @Nullable String resolve()
      Resolves the public IP address of the current machine.
      Returns:
      the public IP address, or null if the lookup fails for any reason