标签:
代码中的链接网站是我找的一个获得对外IP地址的网站,可以根据自己需要替换掉
/// <summary>
/// 获取对外IP地址
/// </summary>
/// <returns></returns>
public static string GetIP()
{
using (var webClient = new WebClient())
{
try
{
var temp = webClient.DownloadString("http://1111.ip138.com/ic.asp");
var ip = Regex.Match(temp, @"\[(?<ip>\d+\.\d+\.\d+\.\d+)]").Groups["ip"].Value;
return !string.IsNullOrEmpty(ip) ? ip : null;
}
catch (Exception ex)
{
return ex.Message;
}
}
}
标签:
原文地址:http://www.cnblogs.com/CareyZhao/p/4615285.html