public IPGeolocationInformation GetInfo(IPAddress ip) { IPGeolocationInformation ipg = new IPGeolocationInformation(ip); string key = this.apikey; string url = "http://api.ipinfodb.com/v3/ip-city/?format=xml&key=" + key + "&ip="; HttpWebResponse res = null; try { var req = WebRequest.Create(url + ip) as HttpWebRequest; XmlDocument xob = null; res = req.GetResponse() as HttpWebResponse; if (req.HaveResponse == true && res != null) { xob = new XmlDocument(); xob.Load(res.GetResponseStream()); if (xob != null) { var x = xob.SelectSingleNode("Response"); if (x != null) { ipg.StatusCode = x["statusCode"].InnerText; ipg.StatusMessage = x["statusMessage"].InnerText; ipg.CountryCode = x["countryCode"].InnerText; ipg.CountryName = x["countryName"].InnerText; ipg.RegionName = x["regionName"].InnerText; ipg.CityName = x["cityName"].InnerText; ipg.ZipCode = x["zipCode"].InnerText; ipg.Latitude = x["latitude"].InnerText; ipg.Longitude = x["longitude"].InnerText; ipg.TimeZone = x["timeZone"].InnerText; } } } } catch { return(null); } finally { if (res != null) { res.Close(); } } return(ipg); }
public IPGeolocationInformation GetInfo(IPAddress ip) { IPGeolocationInformation ipg = new IPGeolocationInformation(ip); string key = this.apikey; string url = "http://api.ipinfodb.com/v3/ip-city/?format=xml&key=" + key + "&ip="; HttpWebResponse res = null; try { var req = WebRequest.Create(url + ip) as HttpWebRequest; XmlDocument xob = null; res = req.GetResponse() as HttpWebResponse; if (req.HaveResponse == true && res != null) { xob = new XmlDocument(); xob.Load(res.GetResponseStream()); if (xob != null) { var x = xob.SelectSingleNode("Response"); if (x != null) { ipg.StatusCode = x["statusCode"].InnerText; ipg.StatusMessage = x["statusMessage"].InnerText; ipg.CountryCode = x["countryCode"].InnerText; ipg.CountryName = x["countryName"].InnerText; ipg.RegionName = x["regionName"].InnerText; ipg.CityName = x["cityName"].InnerText; ipg.ZipCode = x["zipCode"].InnerText; ipg.Latitude = x["latitude"].InnerText; ipg.Longitude = x["longitude"].InnerText; ipg.TimeZone = x["timeZone"].InnerText; } } } } catch { return null; } finally { if (res != null) { res.Close(); } } return ipg; }