private string GetCountryCode(string strIPAddress) { string result = "-"; IP2Location.IPResult oIPResult = new IP2Location.IPResult(); IP2Location.Component oIP2Location = new IP2Location.Component(); try { if (strIPAddress != "") { oIP2Location.IPDatabasePath = Server.MapPath("bin") + "/IPV6-COUNTRY-REGION-CITY.BIN"; // for both IPv4 & IPv6 //oIP2Location.IPDatabasePath = Server.MapPath("bin") + "/IP-COUNTRY-REGION-CITY.BIN"; // for just IPv4 // oIP2Location.IPDatabasePath = @"C:\Program Files\IP2Location\IP2LOCATION-LITE-DB1.IPV6.BIN"; // for both IPv4 & IPv6 //Set License Path oIP2Location.IPLicensePath = Server.MapPath("bin") + "/License.key"; oIPResult = oIP2Location.IPQuery(strIPAddress); if (oIPResult.Status.ToString() == "OK") { result = oIPResult.CountryShort; } } } catch (Exception ex) { } finally { oIPResult = null; oIP2Location = null; } return(result); }
public List <String> getGeoInfo(String ip2Geo) { IP2Location.IPResult oIPResult = new IP2Location.IPResult(); IP2Location.Component oIP2Location = new IP2Location.Component(); List <String> ipInfos = new List <string>(); try { oIP2Location.IPDatabasePath = Environment.CurrentDirectory + @"\\Location DB\\IP2LOCATION-LITE-DB11.BIN"; oIPResult = oIP2Location.IPQuery(ip2Geo); if (oIPResult.Status.ToString().Equals("OK")) { ipInfos.Add(oIPResult.CountryLong); ipInfos.Add(oIPResult.City); ipInfos.Add(oIPResult.Region); ipInfos.Add(oIPResult.ZipCode); ipInfos.Add(oIPResult.TimeZone); return(ipInfos); } else { List <String> errorLists = new List <string>(); errorLists.Add(oIPResult.Status.ToString()); errorLists.Add(oIPResult.Status.ToString()); errorLists.Add(oIPResult.Status.ToString()); errorLists.Add(oIPResult.Status.ToString()); errorLists.Add(oIPResult.Status.ToString()); return(errorLists); } } catch { List <String> errorListse = new List <string>(); errorListse.Add("No Data in DB"); errorListse.Add("No Data in DB"); errorListse.Add("No Data in DB"); errorListse.Add("No Data in DB"); errorListse.Add("No Data in DB"); return(errorListse); } }
public static GeoLocation GetGeoLocation(string strIPAddress) { IP2Location.IPResult oIPResult = new IP2Location.IPResult(); IP2Location.Component oIP2Location = new IP2Location.Component(); try { if (!string.IsNullOrEmpty(strIPAddress)) { oIP2Location.IPDatabasePath = GetGeoDBLocation(); oIPResult = oIP2Location.IPQuery(strIPAddress); switch (oIPResult.Status.ToString()) { case "OK": return(new GeoLocation() { City = oIPResult.City, CountryShort = oIPResult.CountryShort, CountryLong = oIPResult.CountryLong, ZipCode = oIPResult.ZipCode, DomainName = oIPResult.DomainName, InternetServiceProvider = oIPResult.InternetServiceProvider, Latitude = oIPResult.Latitude.ToString(), Longitude = oIPResult.Longitude.ToString() }); } } } catch (Exception ex) { return(null); } finally { oIPResult = null; oIP2Location = null; } return(null); }
static public string GetCountryCode(string strIPAddress) { if (DB_PATH == null) { string path = HttpContext.Current.Server.MapPath("~/App_Data"); DB_PATH = path + "/IP-COUNTRY.BIN"; LIC_PATH = path + "/License.key"; } IP2Location.IPResult oIPResult = new IP2Location.IPResult(); IP2Location.Component oIP2Location = new IP2Location.Component(); try { //Set Database Paths oIP2Location.IPDatabasePath = DB_PATH; oIP2Location.IPLicensePath = LIC_PATH; oIPResult = oIP2Location.IPQuery(strIPAddress); switch (oIPResult.Status.ToString()) { case "OK": return(oIPResult.CountryShort); default: return(null); } } catch (Exception ex) { throw new ApiExitException(ex.Message); } finally { oIPResult = null; oIP2Location = null; } }