首页 > 学院 > 开发设计 > 正文

.net获取本机公网IP代码

2019-11-17 03:25:14
字体:
来源:转载
供稿:网友

.net获取本机公网ip代码

类的代码如下:

 1 using System; 2 using System.Net; 3 using System.Text.RegularExPRessions; 4  5 namespace Keleyi.Com 6 { 7     public class GetInternetIP 8     { 9         public static string GetIP()10         {11             using (var webClient = new WebClient())12             {13                 try14                 {15                     var temp = webClient.DownloadString("http://iframe.ip138.com/ic.asp");16                     var ip = Regex.Match(temp, @"/[(?<ip>/d+/./d+/./d+/./d+)]").Groups["ip"].Value;17                     return !string.IsNullOrEmpty(ip) ? ip : null;18                 }19                 catch (Exception ex)20                 {21                     return ex.Message;22                 }23             }24         }25     }26 }

http://www.VEVb.com/sosoft/


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表