//外网IP
public static string GetIP()
{
using (var webClient = new WebClient())
{
try{
webClient.Credentials = CredentialCache.DefaultCredentials;
byte[] pageDate = webClient.DownloadData("http://pv.sohu.com/cityjson?ie=utf-8");
String ip = Encoding.UTF8.GetString(pageDate);
webClient.Dispose();
Match rebool = Regex.Match(ip, @"\d{2,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}");
return rebool.Value;
}
catch (Exception e)
{
return "";
}
}
}
//本地IP
public static string GetLocalIp()
{
///获取本地的IP地址
string AddressIP = string.Empty;
foreach (IPAddress _IPAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
{
if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
{
AddressIP = _IPAddress.ToString();
}
}
return AddressIP;
}