Validate and Geolocate an IP Address in Java
Did you know that just by looking at information provided by a client’s IP address, you can gain greater insight into their needs? Utilizing the following API can provide you with key intelligence about an IP address, including its location, and whether it’s a bot, botnet, or other form of malware. The location information can be leveraged to better target your users/clients, and the threat identification can guard your business and clients from cyberattacks.

To use this Cloudmersive API, you can install the following SDK with Maven by adding a reference to the repository in pom.xml:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Next, add a reference to the dependency:
<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v3.54</version>
</dependency>
</dependencies>
Then, you can call the function by using the following code:
// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.IpAddressApi;ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
//Apikey.setApiKeyPrefix("Token");IpAddressApi apiInstance = new IpAddressApi();
String value = "value_example"; // String | IP address to process, e.g. \"55.55.55.55\". The input is a string so be sure to enclose it in double-quotes.
try {
IPIntelligenceResponse result = apiInstance.iPAddressIpIntelligence(value);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling IpAddressApi#iPAddressIpIntelligence");
e.printStackTrace();
}
Your results will be returned in no time at all, and this process can be repeated for any IP address you plug into the code. To retrieve your free API key, navigate over to the Cloudmersive website; this will also give you access to 800 monthly API calls.