Prerequisites
- Java 17+ with a Maven or Gradle project
- The
io.ip-api:ipapidependency added - A free ip-api.io API key
Geolocate one IP with lookup(ip)
Pass any IPv4 or IPv6 address, or use lookup() to geolocate the caller's
own IP. Nullable fields may be null — null-check before use.
IpApiClient client = IpApiClient.builder()
.apiKey(System.getenv("IP_API_IO_KEY"))
.build();
IpInfo info = client.lookup("8.8.8.8");
System.out.println(info.ip()); // "8.8.8.8"
System.out.println(info.isp()); // "Google LLC"
System.out.println(info.location().country()); // "United States"
System.out.println(info.suspiciousFactors().isDatacenter()); // true
Resolve the IP of the machine making the request by calling lookup():
IpInfo me = client.lookup();
System.out.println(me.ip()); X-Forwarded-For header to lookup(ip) rather than relying
on the socket address. See the
SDK overview for a Spring Boot example.
Geolocate up to 100 IPs with lookupBatch
Enrich logs, sign-up events, or historical data without a round trip per IP. The SDK throws if the list is empty or longer than 100.
var batch = client.lookupBatch(List.of("8.8.8.8", "1.1.1.1", "9.9.9.9"));
System.out.println(batch.totalProcessed()); // 3
System.out.println(batch.successfulLookups()); // 3
System.out.println(batch.failedLookups()); // 0
batch.results().forEach((ip, info) ->
System.out.println(ip + " " + info.suspiciousFactors().isVpn()));