展会信息港展会大全

.net获取本机公网IP地址的方法
来源:互联网   发布日期:2016-01-26 10:54:24   浏览:1764次  

导读:本文主要介绍了 net获取本机公网IP地址的方法,使用了ip138的数据,大家参考使用吧代码很简单,直接看代码代码如下:using System;using System Net;using System Text RegularExpressions;namespace Keleyi ...

本文主要介绍了.net获取本机公网IP地址的方法,使用了ip138的数据,大家参考使用吧

代码很简单,直接看代码

代码如下:

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;

}

}

}

}

}

赞助本站

人工智能实验室

相关热词: 公网IP地址 net

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港