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 Europian Union, calling code, top level domain (TLD), languages, country flag, internet service provider (ISP), connection type, organization, geoname 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 C# SDK.
Developers can use this C# 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.
// Create IPGeolocationAPI object, passing your valid API keyIPGeolocationAPIapi=newIPGeolocationAPI("YOUR_API_KEY");
Geolocation Lookup
// Get geolocation for IP address (1.1.1.1) and fields (geo, time_zone and currency)GeolocationParamsgeoParams=newGeolocationParams();geoParams.SetIPAddress("1.1.1.1");geoParams.SetFields("geo,time_zone,currency");geoParams.SetIncludeSecurity(true);Dictionary<String,Object>response=api.GetGeolocation(geoParams);// Check if geolocation lookup was successfulif(response["status"]==200){Geolocationgeolocation=(Geolocation)response["response"];Console.WriteLine(geolocation.GetCountryName());Console.WriteLine(geolocation.GetCurrency().GetName());Console.WriteLine(geolocation.GetTimezone().GetCurrentTime());Console.WriteLine(geolocation.GetTimezone().GetCurrentTime());Console.WriteLine(geolocation.GetGeolocationSecurity().GetTor());Console.WriteLine(geolocation.GetGeolocationSecurity().GetProxy());Console.WriteLine(geolocation.GetGeolocationSecurity().GetProxyType());Console.WriteLine(geolocation.GetGeolocationSecurity().GetAnonymous());Console.WriteLine(geolocation.GetGeolocationSecurity().GetThreatScore());Console.WriteLine(geolocation.GetGeolocationSecurity().GetCloudProvider());Console.WriteLine(geolocation.GetUserAgent().GetUserAgentDevice().GetName());}else{Console.WriteLine(response["message"]);}// Get geolocation in Russian** for IP address (1.1.1.1) and all fieldsGeolocationParamsgeoParams=newGeolocationParams();geoParams.SetIPAddress("1.1.1.1");geoParams.SetLang("ru");Dictionary<String,Object>response=api.GetGeolocation(geoParams);// Check if geolocation lookup was successfulif(response["status"]==200){Geolocationgeolocation=(Geolocation)response["response"];Console.WriteLine(geolocation.GetIPAddress());Console.WriteLine(geolocation.GetCountryName());}else{Console.WriteLine(response["message"]);}// Query geolocation for the calling machine's IP address for all fieldsDictionary<String,Object>response=api.GetGeolocation();if(response["status"]==200){Geolocationgeolocation=(Geolocation)response["response"];Console.WriteLine(geolocation.GetCountryCode2());Console.WriteLine(geolocation.GetTimezone().GetCurrentTime());}else{Console.WriteLine(response["message"]);}
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"};GeolocationParamsgeoParams=newGeolocationParams();geoParams.SetIPAddresses(ips);geoParams.SetLang("de");Dictionary<String,Object>response=api.GetBulkGeolocation(geoParams);if(response["status"]==200){List<Geolocation>geolocations=(List<Geolocation>)response["response"];Console.WriteLine(geolocations.Count);Console.WriteLine(geolocations[0].GetCountryName());Console.WriteLine(geolocations[1].GetLanguages());Console.WriteLine(geolocations[2].GetTimezone().GetCurrentTime());}else{Console.WriteLine(response["message"]);}// Query geolocations for multiple IP addresses but only geo fieldString[]ips=newString[]{"1.1.1.1","2.2.2.2","3.3.3.3"};GeolocationParamsgeoParams=newGeolocationParams();geoParams.SetIPAddresses(ips);geoParams.SetFields("geo");Dictionary<String,Object>response=api.GetBulkGeolocation(geoParams);if(response["status"]==200){List<Geolocation>geolocations=(List<Geolocation>)response["response"];Console.WriteLine(geolocations.Count);Console.WriteLine(geolocations[0].GetCountryCode2());Console.WriteLine(geolocations[0].GetCountryName());Console.WriteLine(geolocations[0].GetLatitude());}else{Console.WriteLine(response["message"]);}
Timezone API
// Query time zone information by time zone IDTimezoneParamstzParams=newTimezoneParams();tzParams.SetTimezone("America/New_York");Dictionary<String,Object>response=api.GetTimezone(tzParams);if(response["status"]==200){Timezonetz=(Timezone)response["response"];Console.WriteLine(tz.GetDateTimeWti());Console.WriteLine(tz.GetDateTimeTxt());}else{Console.WriteLine(response["message"]);}// Query time zone information by latitude and longitude of the locationTimezoneParamstzParams=newTimezoneParams();tzParams.SetCoordinates(37.1838139,-123.8105225);Dictionary<String,Object>response=api.GetTimezone(tzParams);if(response["status"]==200){Timezonetz=(Timezone)response["response"];Console.WriteLine(tz.GetTimezone());}else{Console.WriteLine(response["message"]);}// Get time zone information for IP address (1.1.1.1) and geolocation information Japanese**TimezoneParamstzParams=newTimezoneParams();tzParams.SetIPAddress("1.1.1.1");tzParams.SetLang("ja");Dictionary<String,Object>response=api.GetTimezone(tzParams);if(response["status"]==200){Timezonetz=(Timezone)response["response"];Console.WriteLine(tz.GetTimezone());}else{Console.WriteLine(response["message"]);}// Query time zone information for calling machine’s IP addressDictionary<String,Object>response=api.GetTimezone();if(response["status"]==200){Timezonetz=(Timezone)response["response"];Console.WriteLine(tz.GetTimezone());Console.WriteLine(tz.GetDateTimeYmd());}else{Console.WriteLine(response["message"]);}
** IPGeolocation provides geolocation information in the following languages:
English (en)
German (de)
Russian (ru)
Japanese (ja)
French (fr)
Chinese Simplified (cn)
Spanish (es)
Czech (cs)
Italian (it)
By default, geolocation information is returned in English. Response in a language other than English is available to paid users only.
IP Geolocation API C# SDK Objects Reference
IP Geolocation API C# SDK has following classes that you can use to fully leverage it.
Class: IPGeolocation.IPGeolocationAPI
Method
Description
Return Type
IPGeolocationAPI(String apiKey)
Constructs the IPGeolocationAPI object and takes a valid apiKey as parameter. It throws ArgumentException for empty/null apiKey.
GetApiKey()
This function to get the API key that you set to query the IPGeolocation API.
This function to query Geolocation API to lookup multiple IP addresses (max. 50).
Dictionary<String, Object>
GetTimezone()
This function to query Timezone API based on calling machine's IP address.
Dictionary<String, Object>
GetTimezone(TimezoneParams timezoneParams)
This function to query Timezone API based on the parameters passed.
Dictionary<String, Object>
GetUserAgent(String uaString)
This function to query UserAgent API.
Dictionary<String, Object>
GetBulkUserAgent(List uaStrings)
This function to query UserAgent API to lookup multiple user-agent strings (max. 50).
Dictionary<String, Object>
Class: IPGeolocation.GeolocationParams
Method
Description
Return Type
SetIPAddress(String ipAddress)
Sets IP address to lookup geolocation.
void
GetDomain()
Get domain name when domain name is passed.
String
GetHostname()
Get hostname for the IP address.
String
GetIPAddress()
Get IP address set to lookup geolocation.
String
SetIPAddresses(String[] ipAddresses)
Set IP addresses to lookup multiple geo-locations. Throws IllegalArgumentException if no. of IP addresses are more than 50. Note: Multiple IP addresses lookup is only available for paid users.
void
GetIPAddresses()
Get IP addresses set to lookup bulk geolocations.
String[]
SetLang(String lang)
Set language parameter to lookup geolocation.
void
GetLang()
Get language set to lookup geolocation.
String
SetFields(String fields)
Set fields to lookup geolocation.
void
GetFields()
Get fields set to lookup geolocation.
String
SetIncludeHostname(Boolean includeHostname)
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.
void
IsIncludeHostname()
Returns Boolean object whether hostname is included in response or not.
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.
void
IsIncludeHostnameFallbackLive()
Returns Boolean object whether hostname with fall-back-live is included in response or not.
This URL parameter enables the IPGeolocation API to lookup hostname from live sources. Lookup thru live sources is accurate but can introduce more latency to your query to IPGeolocation API.
void
IsIncludeLiveHostname()
Returns Boolean object whether live hostname is included in response or not.
Boolean
SetIncludeSecurity(Boolean includeSecurity)
Set includeSecurity to true to get Security object as well.
void
IsIncludeSecurity()
Returns Boolean object whether Security object is included in response or not.