using System;
using System.Net;
using System.Text.RegularExpressions;
namespace GetInternetIP
{
public class GetInternetIP
{
public static string GetIP()
{
using (var webClient = new WebClient())
{
try
{
var temp = webClient.DownloadString("http://iframe.ip138.com/ic.asp");
return Regex.Match(temp, @"\[(?<ip>\d+\.\d+\.\d+\.\d+)]").Groups["ip"].Value;
}
catch (Exception ex)
{
return ex.Message;
}
}
}
}
}
C#獲取本機公網IP
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.