public static IpAddressModel GetDetailIp(string IpAddress)
{
string url = "http://ip-api.com/json/" + IpAddress + "?lang=zh-CN";
WebRequest wrt = null;
WebResponse wrp = null;
wrt = WebRequest.Create(url);
wrt.Credentials = CredentialCache.DefaultCredentials;
wrp = wrt.GetResponse();
StreamReader sr = new StreamReader(wrp.GetResponseStream(), Encoding.UTF8);
//获取到的是Json数据
string html = sr.ReadToEnd();
IpAddressModel m = JsonConvert.DeserializeObject<IpAddressModel>(html);
return m;
}
public class IpAddressModel
{
public string status { get; set; }
public string country { get; set; }
public string countryCode { get; set; }
public string region { get; set; }
public string regionName { get; set; }
public string city { get; set; }
public string zip { get; set; }
public double lat { get; set; }
public double lon { get; set; }
public string timezone { get; set; }
public string isp { get; set; }
public string org { get; set; }
public string query { get; set; }
}