[C#] 纯文本查看 复制代码
/// <summary>
/// 获取IP归属地
/// </summary>
/// <param name="Ip">IP地址</param>
/// <returns></returns>
public string GetIpAddRess(string Ip)
{
WebRequest request = WebRequest.Create("http://www.ip138.com/ips138.asp?ip=" + Ip);
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gb2312"));
string read = reader.ReadToEnd();
Regex regex = new Regex("<td align=\"center\"><ul class=\"ul1\"><li>本站主数据:(?<title>.*?)</li>");
if (regex.IsMatch(read))
{
read = regex.Match(read).Groups["title"].Value;
}
return read;
}