using System.Net; using System.Text; using System.Text.RegularExpressions; private string GetIp() { WebClient client = new WebClient(); byte[] bytRecv = client.DownloadData("http://www.ip138.com/ip2city.asp"); string str = Encoding.GetEncoding("gb2312").GetString(bytRecv); string regexStr = @"(((/d{1,2})|(1/d{2})|(2[0-4]/d)|(25[0-5]))/.){3}((/d{1,2})|(1/d{2})|(2[0-4]/d)|(25[0-5]))"; string myip = Regex.Match(str, regexStr).ToString(); return myip; }