.net获取本机公网IP代码

类的代码如下:

 using System;
using System.Net;
using System.Text.RegularExpressions; namespace Keleyi.Com
{
public class GetInternetIP
{
public static string GetIP()
{
using (var webClient = new WebClient())
{
try
{
var temp = webClient.DownloadString("http://iframe.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/sosoft/

上一篇:uva 1599 ideal path(好题)——yhx


下一篇:Mac 命令行查看自己的公网IP