星空网 > 软件开发 > ASP.net

.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;        }      }    }  }}

  




原标题:.net获取本机公网IP代码

关键词:.NET

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流