源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

.net获取本机公网IP地址示例

  • 时间:2021-08-28 19:53 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:.net获取本机公网IP地址示例
代码很简单,直接看代码
[u]复制代码[/u] 代码如下:
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;                 }             }         }     } }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部