Java SDK · Feature

IP Geolocation in Java

Turn any IP address into geolocation, network, and threat intelligence with one call. The lookup method on the official io.ip-api:ipapi client returns the country, city, coordinates, timezone, ISP, and ASN of an IP — plus the suspiciousFactors() flags used for fraud screening — in a single typed response.

Trusted by thousands of businesses
Fast JSON API responses
Real-time validation
Simple integration, SDKs & examples
What it does

Geolocation without browser GPS

IP-based geolocation works entirely server-side — no permission prompt, no client SDK, and it works for every visitor and every log line you already have. ip-api.io resolves an IP to a physical location and, uniquely, returns security signals (VPN, proxy, Tor, datacenter, threat) in the same response, so you can localize content and screen for fraud in one round trip.

Prerequisites

  • Java 17+ with a Maven or Gradle project
  • The io.ip-api:ipapi dependency added
  • A free ip-api.io API key
1

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());
Behind a proxy? Pass the real client IP from the X-Forwarded-For header to lookup(ip) rather than relying on the socket address. See the SDK overview for a Spring Boot example.
2

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()));
Reference

Response reference

lookup returns a typed IpInfo record. Nullable fields may be null for private or unrecognized addresses.

AccessorTypeDescription
ip()StringThe looked-up address
isp()StringInternet service provider
asn()StringAutonomous system the IP belongs to
location()Locationcountry(), countryCode(), city(), latitude(), longitude(), zip(), timezone(), localTime(), localTimeUnix(), isDaylightSavings() (nullable)
suspiciousFactors()SuspiciousFactorsisProxy(), isVpn(), isTorNode(), isDatacenter(), isSpam(), isCrawler(), isThreat()
FAQ

Frequently asked questions

How do I get the location of an IP address in Java?

Add io.ip-api:ipapi, build an IpApiClient with your API key, and call client.lookup(ip). The returned IpInfo record has a location() record with country, city, latitude, longitude and timezone, plus a suspiciousFactors() record with VPN/proxy/Tor flags.

How do I geolocate the caller's own IP?

Call client.lookup() with no IP argument and the API resolves the IP from the request. Behind a proxy, pass the real client IP from the X-Forwarded-For header to client.lookup(ip) instead.

How do I look up many IP addresses at once?

Use client.lookupBatch(ips) with up to 100 addresses in one request. It returns results() (a Map<String, IpInfo>) plus totalProcessed(), successfulLookups() and failedLookups().

Why are some fields nullable?

Nullable location fields such as country() and city() may return null for private ranges or unrecognized addresses — null-check before use. Boolean flags like isVpn() are primitive boolean.

Start building with the ip-api.io Java SDK

Add io.ip-api:ipapi to your build, drop in your free API key, and ship in minutes — one client for geolocation, fraud detection, and email validation.

Need support?

Explore how IP-API.io can enhance your security, provide robust bot protection, and improve IP geolocation accuracy for your applications.

Contact Support

Found a bug in the SDK?

The io.ip-api:ipapi library is open source. Open an issue or pull request on GitHub and we'll take a look.

Open on GitHub