- private string GetIpData(string ipStr){
- string ipData = string.Empty;
- string linkUrl = "http://whois.pconline.com.cn/ip.jsp";
- linkUrl = string.IsNullOrEmpty(ipStr) ? linkUrl : linkUrl + "?ip=" + ipStr;
- try
- {
- webRequest request = WebRequest.Create(linkUrl);
- WebResponse response = request.GetResponse();
- StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312"));
- ipData = reader.ReadToEnd();
- reader.Close();
- reader.Dispose();
- response.Close();
- }
- catch (Exception)
- {
- }
- return string.IsNullOrEmpty(ipData) ? "" : ipData.Substring(0, ipData.Length - 1) + " ";
- }
- //该片段来自于http://www.codesnippet.cn/detail/1206201512848.html
来源: http://www.codesnippet.cn/detail/1206201512848.html