Get Address,City,County From IP address

First you must create account on Here to get API_Key
you can read document from Here
once you get API_Key you can use Code to get data :

private String GetCityName(string IP) { string _City = ""; try { string _URL = null; string _ApiKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; _URL = "http://api.ipinfodb.com/v3/ip-country/?key=" + _ApiKey + "&format=xml&ip=" + IP; //Get google response as XML doc dynamic xmlDoc = new System.Xml.XmlDocument(); xmlDoc.Load(_URL); System.Xml.XmlNode _root = xmlDoc.DocumentElement; System.Xml.XmlNodeList _CityName = xmlDoc.GetElementsByTagName("cityName"); System.Xml.XmlElement _CityNameElement = (System.Xml.XmlElement)_CityName.Item(0); _City = _CityNameElement.FirstChild.Value; } catch (Exception ex) { _City = "CANADA"; } //End Try return _City; }




Comments

Popular posts from this blog

C# Crop white space from around the image

Could not load file or assembly 'Microsoft.ReportViewer.Common, Version=xx.0.0.0, Culture=neutral, PublicKeyToken='xxx' or one of its dependencies.

The specified version string contains wildcards, which are not compatible with determinism.