You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
IPGeolocation API is the solution to identify country code (ISO2 and ISO3 standard), country
name, continent code, continent name, country capital, state/province, district, city, zip code, latitude and longitude
of city, is country belongs to European Union, calling code, top level domain (TLD), languages, country flag, internet
service provider (ISP), connection type, organization, geo name ID, currency code, currency name, time zone ID, time zone
offset, current time in the time zone, is time zone in daylight saving time, total daylight savings and user agent
details. This document provides important information to help you get up to speed with IPGeolocation API using IP
Geolocation API Java SDK.
Developers can use this Java SDK for software and web projects related to, but not limited to:
Display native language and currency
Redirect based on the country
Digital rights management
Web log stats and analysis
Auto-selection of country, state/province and city on forms
Filter access from countries you do not do business with
Geo-targeting for increased sales and click-through
Quick Start Guide
You need a valid 'IPGeolocation API key' to use this SDK. Sign up here and get your
free API key if you don’t have one.
// Get geolocation in Russian** for IP address (1.1.1.1) and all fieldsGeolocationParamsgeolocationParams =
GeolocationParams.builder()
.withIPAddress("1.1.1.1")
.withLang("ru")
.build();
try {
Geolocationgeolocation = ipGeolocationAPI.getGeolocation(geolocationParams);
System.out.println("IP Address: " + geolocation.getIP());
System.out.println("Country: " + geolocation.getCountryName());
} catch (IPGeolocationErrore) {
// on unsuccessful lookup or invalid input IPGeolocationError is thrownSystem.err.println("HTTP status: " + e.getStatus() + " Error: " + e.getMessage());
}
// Get geolocation for the calling machine's IP address for all fieldstry {
Geolocationgeolocation = ipGeolocationAPI.getGeolocation();
System.out.println("IP Address: " + geolocation.getIP());
System.out.println("Country Code ISO2: " + geolocation.getCountryCode2());
System.out.println("Location time: " + geolocation.getTimezone().getCurrentTime());
} catch (IPGeolocationErrore) {
// on unsuccessful lookup or invalid input IPGeolocationError is thrownSystem.err.println("HTTP status: " + e.getStatus() + " Error: " + e.getMessage());
}
Bulk Geolocations Lookup
// Query geolocation in German** for multiple IP addresses and all fieldsString[] ips = newString[]{"1.1.1.1", "2.2.2.2", "3.3.3.3"};
GeolocationParamsgeolocationParams =
GeolocationParams.builder()
.withLang("de")
.build();
try {
List<Geolocation> geolocations = ipGeolocationAPI.getBulkGeolocation(ips, geolocationParams);
System.out.println("No. of Requests: " + geolocations.size());
System.out.println("1st IP's Country: " + geolocations.get(0).getCountryName());
System.out.println("2nd IP's Language: " + geolocations.get(1).getLanguages());
System.out.println("3rd IP's location time: " + geolocations.get(2).getTimezone().getCurrentTime());
} catch (IPGeolocationErrore) {
// on unsuccessful lookup or invalid input IPGeolocationError is thrownSystem.err.println("HTTP status: " + e.getStatus() + " Error: " + e.getMessage());
}
// Query geolocations for multiple IP addresses but only geo fieldString[] ips = newString[]{"1.1.1.1", "2.2.2.2", "3.3.3.3"};
GeolocationParamsgeolocationParams =
GeolocationParams.builder()
.withFields("geo")
.build();
try {
List<Geolocation> geolocations = ipGeolocationAPI.getBulkGeolocation(ips, geolocationParams);
System.out.println("No. of Requests: " + geolocations.size());
System.out.println("1st IP's Country: " + geolocations.get(0).getCountryName());
System.out.println("2nd IP's City: "+geolocations.get(1).getCity());
System.out.println("3rd IP's City Zipcode: " + geolocations.get(2).getZipCode());
} catch (IPGeolocationErrore) {
// on unsuccessful lookup or invalid input IPGeolocationError is thrownSystem.err.println("HTTP status: " + e.getStatus() + " Error: " + e.getMessage());
}
Timezone API
// Get time zone information by time zone IDTimezoneParamstimezoneParams =
TimezoneParams.builder().withTimeZone("America/New_York").build();
try {
Timezonetz = ipGeolocationAPI.getTimezone(timezoneParams);
System.out.println("Format 'EEEE, MMMM dd, yyyy HH:mm:ss': " + tz.getDateTimeTxt());
System.out.println("Format 'EEE, dd MMM yyyy HH:mm:ss Z': " + tz.getDateTimeWti());
} catch (IPGeolocationErrore) {
// on unsuccessful lookup or invalid input IPGeolocationError is thrownSystem.err.println("HTTP status: " + e.getStatus() + " Error: " + e.getMessage());
}
// Get time zone information by coordinates (latitude and longitude) of the locationTimezoneParamstimezoneParams =
TimezoneParams.builder()
.withCoordinates(BigDecimal.valueOf(37.1838139), BigDecimal.valueOf(-123.8105225))
.build();
try {
Timezonetz = ipGeolocationAPI.getTimezone(timezoneParams);
System.out.println("Timezone: " + tz.getTimezone());
System.out.println("Timezone in Unix: " + tz.getDateTimeUnix());
System.out.println("Time in 24 format: " + tz.getTime24());
} catch (IPGeolocationErrore) {
// on unsuccessful lookup or invalid input IPGeolocationError is thrownSystem.err.println("HTTP status: " + e.getStatus() + " Error: " + e.getMessage());
}
// Get time zone information for IP address (1.1.1.1) and geolocation information in Japanese**TimezoneParamstimezoneParams =
TimezoneParams.builder()
.withIPAddress("1.1.1.1")
.withLang("ja")
.build();
try {
Timezonetz = ipGeolocationAPI.getTimezone(timezoneParams);
// Timezone InfoSystem.out.println("Timezone: " + tz.getTimezone());
System.out.println("Format 'EEEE, MMMM dd, yyyy HH:mm:ss': " + tz.getDateTimeTxt());
System.out.println("Format 'yyyy-MM-dd'T'HH:mm:ssZ': " + tz.getDateTimeYmd());
// Geo InfoSystem.out.println("City: " + tz.getGeo().getCity());
System.out.println("State/Province: " + tz.getGeo().getStateProvince());
System.out.println("Country: " + tz.getGeo().getCountryName());
} catch (IPGeolocationErrore) {
// on unsuccessful lookup or invalid input IPGeolocationError is thrownSystem.err.println("HTTP status: " + e.getStatus() + " Error: " + e.getMessage());
}
// Query time zone information for calling machine's IP addresstry {
Timezonetz = ipGeolocationAPI.getTimezone();
// Timezone InfoSystem.out.println("Timezone Offset: " + tz.getTimezoneOffset());
System.out.println("Date: " + tz.getDate());
System.out.println("Month (No.): " + tz.getMonth());
// Geo InfoSystem.out.println("City: " + tz.getGeo().getCity());
System.out.println("Country Code ISO3: " + tz.getGeo().getCountryCode3());
System.out.println("Lat/Lon: " + tz.getGeo().getLatitude() + "/" + tz.getGeo().getLongitude());
} catch (IPGeolocationErrore) {
// on unsuccessful lookup or invalid input IPGeolocationError is thrownSystem.err.println("HTTP status: " + e.getStatus() + " Error: " + e.getMessage());
}
// Get time zone information by location (city, country, etc.)TimezoneParamstimezoneParams =
TimezoneParams.builder().withLocation("Syria, Damascus").build();
try {
Timezonetz = ipGeolocationAPI.getTimezone(timezoneParams);
System.out.println("Format 'EEEE, MMMM dd, yyyy HH:mm:ss': " + tz.getDateTimeTxt());
System.out.println("Country: " + tz.getGeo().getCountryName());
} catch (IPGeolocationErrore) {
// on unsuccessful lookup or invalid input IPGeolocationError is thrownSystem.err.println("HTTP status: " + e.getStatus() + " Error: " + e.getMessage());
}
UserAgent API
// Query/Parse user agent information for Provided the provided stringtry {
StringuaString = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9";
UserAgentua = ipGeolocationAPI.getUserAgent(uaString);
System.out.println("Device name: " + ua.getDevice().getName());
System.out.println("OS name: " + ua.getOperatingSystem().getName());
System.out.println("OS version: " + ua.getOperatingSystem().getVersion());
System.out.println("CPU: " + ua.getDevice().getCpu());
} catch (IPGeolocationErrore) {
// on unsuccessful lookup or invalid input IPGeolocationError is thrownSystem.err.println("HTTP status: " + e.getStatus() + " Error: " + e.getMessage());
}
// Query/Parse user agent information for the provided stringsString[] uaStrings = newString[]
{"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9",
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36",
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1"};
try {
List<UserAgent> uas = ipGeolocationAPI.getBulkUserAgent(uaStrings);
System.out.println("No. of Requests: " + uas.size());
System.out.println("1st UA's Device name: " + uas.get(0).getDevice().getName());
System.out.println("2nd UA's OS name: " + uas.get(1).getOperatingSystem().getName());
System.out.println("3rd UA's Browser: " + uas.get(2).getName());
} catch (IPGeolocationErrore) {
System.err.println("HTTP status: " + e.getStatus() + " Error: " + e.getMessage());
}
// Query useragent of the machine IP Address along with GeolocationGeolocationParamsgeolocationParams =
GeolocationParams.builder()
.includeUserAgentDetail()
.build();
try {
Geolocationgeolocation = ipGeolocationAPI.getGeolocation(geolocationParams);
System.out.println("IP: " + geolocation.getIP());
System.out.println("City: " + geolocation.getCity());
System.out.println("UserAgent OS: " + geolocation.getUserAgent().getOperatingSystem().getName());
System.out.println("UserAgent Browser:" + geolocation.getUserAgent().getName());
System.out.println("UserAgent Device: " + geolocation.getUserAgent().getDevice().getName());
} catch (IPGeolocationErrore) {
// on unsuccessful lookup or invalid input IPGeolocationError is thrownSystem.err.println("HTTP status: " + e.getStatus() + " Error: " + e.getMessage());
}
This URL parameter enables the IPGeolocation API to lookup hostname from our IP-Hostname database and returns the same IP address if there is no hostname found for the queried IP address. Lookup thru IP-Hostname database is faster than other options but is experimental and under process and can produce unwanted output.
GeolocationParamsBuilder
includeHostnameFallbackLive()
This URL parameter enables the IPGeolocation API to lookup hostname from our IP-Hostname database and if there is no hostname found for the queried IP address, then lookup thru the live sources. This option has been introduced for faster and accurate lookup.
GeolocationParamsBuilder
includeLiveHostname()
Returns Boolean object whether live hostname is included in response or not.
GeolocationParamsBuilder
includeSecurity()
Returns Boolean object whether Security object is included in response or not.
GeolocationParamsBuilder
includeUserAgentDetail()
Returns Boolean object whether UserAgent object is included in response or not.
GeolocationParamsBuilder
withExcludes(String excludes)
Set fields (as a comma separated value) to exclude from response.
GeolocationParamsBuilder
build()
Returns an instance of GeolocationParams with the values set earlier.
GeolocationParams
Class: io.ipgeolocation.api.Geolocation
Method
Description
Return Type
getDomain()
Returns domain name if domain name is passed.
String
getHostname()
Returns hostname for the IP address.
String
getIP()
Returns IP address of the geolocation.
String
getContinentCode()
Returns 2-letters continent code.
String
getContinentName()
Returns continent name.
String
getCountryCode2()
Returns 2-letters country code.
String
getCountryCode3()
Returns 3-letters country code.
String
getCountryName()
Returns country name.
String
getCountryCapital()
Returns country capital.
String
getStateProvince()
Returns state/province.
String
getStateCode()
Returns the ISO code for state/province.
String
getDistrict()
Returns district.
String
getCity()
Returns city.
String
getZipCode()
Returns zip code.
String
getLatitude()
Returns latitude of the city.
BigDecimal
getLongitude()
Returns longitude of the city.
BigDecimal
isEU()
Returns is the country in European Union.
boolean
getCallingCode()
Returns country calling code.
String
getCountryTLD()
Returns country's top level domain like '.au' for Australia.
String
getLanguages()
Returns languages spoken in the country.
String
getCountryFlag()
Returns a URL to country's flag.
String
getISP()
Returns ISP name.
String
getConnectionType()
Returns connection type of the IP address.
String
getOrganization()
Returns organization of the IP address.
String
getAsn()
Returns AS number of the IP address.
String
getGeoNameId()
Returns Geo Name ID from geonames.org database.
String
getCurrency()
Returns currency information of the country.
GeolocationCurrency
getTimezone()
Returns time zone information of the country.
GeolocationTimezone
getGeolocationSecurity()
Returns security details of the ip address.
GeolocationSecurity
getUserAgent()
Returns user agent information of the country.
UserAgent
Class: io.ipgeolocation.api.GeolocationCurrency
Method
Description
Return Type
getName()
Returns currency name.
String
getCode()
Returns 3-letters currency code.
String
getSymbol()
Returns currency symbol.
String
Class: io.ipgeolocation.api.GeolocationTimezone
Method
Description
Return Type
getName()
Returns standard time zone ID like "America/New_York".
String
getOffset()
Returns time zone offset from UTC.
int
getCurrentTime()
Returns current date-time string in the format "yyyy-MM-dd HH:mm:ss.SSSZ"
String
getCurrentTimeUnix()
Returns current date-time as a unix time
BigDecimal
isDST()
Returns is the country observing daylight saving time.
Boolean
getDSTSavings()
Returns daylight savings time (in hours).
int
getOffsetWithDst()
Returns daylight savings time offset with UTC (in hours).
int
Class: io.ipgeolocation.api.GeolocationSecurity
Method
Description
Return Type
getThreatScore()
Returns threat score for the ip address
int
isTor()
Returns Boolean object whether the ip is using tor or not.
boolean
isProxy()
Returns Boolean object whether the ip is using proxy or not.
boolean
getProxyType()
Returns the type of proxy used by ip address
String
isAnonymous()
Returns Boolean object whether the ip is anonymous or not.
boolean
isKnownAttacker()
Returns Boolean object whether the ip is known attacker or not.
boolean
isBot()
Returns Boolean object whether the ip is bot or not.
boolean
isSpam()
Returns Boolean object whether the ip is spam or not.
boolean
isCloudProvider()
Returns Boolean object whether the ip is cloud provider or not.
boolean
Class: io.ipgeolocation.api.TimezoneParams
Method
Description
Return Type
getTimezone()
Get time zone ID set to query time zone information.
String
getIPAddress()
Get IP address set to query time zone information.
String
getLatitude()
Returns latitude set to query time zone information.
BigDecimal
getLongitude()
Returns longitude set to query time zone information.
BigDecimal
getLocation()
Get location parameter value to get timezone details.