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
最新推荐文章于 2023-12-20 21:20:48 发布