在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
/// <summary> /// get country and city /// </summary> /// <param name="ip"></param> /// <returns></returns> public static List<string> IPGetCity(string ip) { var country = ""; var city = ""; var list = new List<string>(); try { WebClient MyWebClient = new WebClient(); MyWebClient.Credentials = CredentialCache.DefaultCredentials;//获取或设置用于向Internet资源的请求进行身份验证的网络凭据 Byte[] pageData = MyWebClient.DownloadData("http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=" + ip); //从指定网站下载数据 string pageHtml = Encoding.Default.GetString(pageData); dynamic data = Newtonsoft.Json.JsonConvert.DeserializeObject(pageHtml); if (pageHtml.Contains("country")&& pageHtml.Contains("city")) { country = data.country; city = data.city; } list.Add(country); list.Add(city); return list; } catch (Exception ex) { list.Add(country); list.Add(city); return list; } }
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论