using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Net; using System.Web.Script.Serialization; using System.Web.UI.WebControls; public partial class getipaddress_test : System.Web.UI.Page { public class Location { public string IPAddress { get; set; } public string CountryName { get; set; } public string CountryCode { get; set; } public string CityName { get; set; } public string RegionName { get; set; } public string ZipCode { get; set; } public string Latitude { get; set; } public string Longitude { get; set; } public string TimeZone { get; set; } } protected void Page_Load(object sender, EventArgs e) { string ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (string.IsNullOrEmpty(ipAddress)) { ipAddress = Request.ServerVariables["REMOTE_ADDR"]; } string APIKey = "<your api="" key="">"; string url = string.Format("http://api.ipinfodb.com/v3/ip-city/?key=7d0f9f121cca47d87c9ad6da04748bcd04a43387b21960902b6c9b6d4a84b34z&ip={1}&format=json", APIKey, ipAddress); using (WebClient client = new WebClient()) { string json = client.DownloadString(url); //string v_cn = ("cityname"); Location location = new JavaScriptSerializer().Deserialize<location>(json); List<location> locations = new List<location>(); locations.Add(location); gvLocation.DataSource = locations; gvLocation.DataBind(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)