zoukankan      html  css  js  c++  java
  • IP地址工具类

      /// <summary>
            /// 获取客户端IP地址
            /// </summary>
            /// <returns></returns>
            public static string GetHostAddress()
            {
                string userHostAddress = HttpContext.Current.Request.UserHostAddress;
                if (string.IsNullOrEmpty(userHostAddress))
                {
                    userHostAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                }
    
                //最后判断获取是否成功,并检查IP地址的格式(检查其格式非常重要)
                if (!string.IsNullOrEmpty(userHostAddress) && IsIP(userHostAddress))
                {
                    return userHostAddress;
                }
                return "127.0.0.1";
            }
    
            public static bool IsIP(string ip)
            {
                return System.Text.RegularExpressions.Regex.IsMatch(ip, @"^((2[0-4]d|25[0-5]|[01]?dd?).){3}(2[0-4]d|25[0-5]|[01]?dd?)$");
            }
    

      

  • 相关阅读:
    OpenCV 简介
    无缝滚动
    Date 与 switch的运用
    js object(对象)
    arr.sort()排序方法
    删除
    评分
    延时提示框
    数字相加求和
    自定义右键菜单
  • 原文地址:https://www.cnblogs.com/shanshanlaichi/p/6887952.html
Copyright © 2011-2022 走看看