代码很简单,直接看代码
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;
}
}
}
}
}
- asp.net 获取客户端浏览器访问的IP地址的实例代码
- 用IIS建立的.net网站通过IP地址不能访问解决方法
- asp.net获取URL和IP地址的方法汇总
- ASP.NET获取真正的客户端IP地址的6种方法
- jquery的ajax从纯真网(cz88.net)获取IP地址对应地区名
- asp.net DZ论坛中根据IP地址取得所在地的代码
- .Net获取IP地址的方法
本文由 华域联盟 原创撰写:华域联盟 » .net获取本机公网IP地址示例
转载请保留出处和原文链接:https://www.cnhackhy.com/53227.htm