Ejemplo n.º 1
0
        public static string GetUserIP()
        {
            if (HttpContext.Current == null)
            {
                return(string.Empty);
            }
            string ipval = string.Empty;

            ipval = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            switch (ipval)
            {
            case null:
            case "":
                ipval = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                break;
            }
            if ((ipval == null) || (ipval == string.Empty))
            {
                ipval = HttpContext.Current.Request.UserHostAddress;
            }
            if (!(((ipval != null) && (ipval != string.Empty)) && Validate.IsIP(ipval)))
            {
                return("0.0.0.0");
            }
            return(ipval);
        }
Ejemplo n.º 2
0
 public static bool InIPArray(string ip, string[] ipArray)
 {
     if (!string.IsNullOrEmpty(ip) && Validate.IsIP(ip))
     {
         string[] array = TextUtility.SplitStrArray(ip, ".");
         for (int i = 0; i < ipArray.Length; i++)
         {
             string[] array2 = TextUtility.SplitStrArray(ipArray[i], ".");
             int      num    = 0;
             for (int j = 0; j < array2.Length; j++)
             {
                 if (array2[j] == "*")
                 {
                     return(true);
                 }
                 if (array.Length <= j || array2[j] != array[j])
                 {
                     break;
                 }
                 num++;
             }
             if (num == 4)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Ejemplo n.º 3
0
        public static string GetUserIP()
        {
            if (HttpContext.Current == null)
            {
                return(string.Empty);
            }
            string text = string.Empty;

            text = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            string a;

            if ((a = text) == null || a == "")
            {
                text = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            }
            if (text == null || text == string.Empty)
            {
                text = HttpContext.Current.Request.UserHostAddress;
            }
            if (text == null || !(text != string.Empty) || !Validate.IsIP(text))
            {
                return("0.0.0.0");
            }
            return(text);
        }
Ejemplo n.º 4
0
 public static int ConvertVersionStr2Int(string strVersion)
 {
     if (!Validate.IsIP(strVersion))
     {
         return(0);
     }
     string[] strArray = strVersion.Split(new char[] { '.' });
     return((((System.Convert.ToInt32(strArray[0]) << 0x18) | (System.Convert.ToInt32(strArray[1]) << 0x10)) | (System.Convert.ToInt32(strArray[2]) << 8)) | System.Convert.ToInt32(strArray[3]));
 }
Ejemplo n.º 5
0
 public static int ConvertVersionStr2Int(string strVersion)
 {
     if (!Validate.IsIP(strVersion))
     {
         return(0);
     }
     string[] array = strVersion.Split('.');
     return((System.Convert.ToInt32(array[0]) << 24) | (System.Convert.ToInt32(array[1]) << 16) | (System.Convert.ToInt32(array[2]) << 8) | System.Convert.ToInt32(array[3]));
 }
Ejemplo n.º 6
0
 public static int ConvertVersionStr2Int(string strVersion)
 {
     if (!Validate.IsIP(strVersion))
     {
         return(0);
     }
     string[] array = strVersion.Split(new char[]
     {
         '.'
     });
     return(System.Convert.ToInt32(array[0]) << 24 | System.Convert.ToInt32(array[1]) << 16 | System.Convert.ToInt32(array[2]) << 8 | System.Convert.ToInt32(array[3]));
 }
Ejemplo n.º 7
0
        public static long IP2Int(string ip)
        {
            if (!Validate.IsIP(ip))
            {
                return(-1L);
            }
            string[] strArray = ip.Split(new char[] { '.' });
            long     num      = long.Parse(strArray[3]) * 0x1000000L;

            num += int.Parse(strArray[2]) * 0x10000;
            num += int.Parse(strArray[1]) * 0x100;
            return(num + int.Parse(strArray[0]));
        }
Ejemplo n.º 8
0
        public static long IP2Int(string ip)
        {
            if (!Validate.IsIP(ip))
            {
                return(-1L);
            }
            string[] array = ip.Split('.');
            long     num   = long.Parse(array[3]) * 16777216;

            num += int.Parse(array[2]) * 65536;
            num += int.Parse(array[1]) * 256;
            return(num + int.Parse(array[0]));
        }
Ejemplo n.º 9
0
        public static string GetServerDomain()
        {
            string ipval = HttpContext.Current.Request.Url.Host.ToLower();

            if ((ipval.Split(new char[] { '.' }).Length < 3) || Validate.IsIP(ipval))
            {
                return(ipval);
            }
            string str2 = ipval.Remove(0, ipval.IndexOf(".") + 1);

            if (((str2.StartsWith("com.") || str2.StartsWith("net.")) || str2.StartsWith("org.")) || str2.StartsWith("gov."))
            {
                return(ipval);
            }
            return(str2);
        }
Ejemplo n.º 10
0
        public static long IP2Int(string ip)
        {
            if (!Validate.IsIP(ip))
            {
                return(-1L);
            }
            string[] array = ip.Split(new char[]
            {
                '.'
            });
            long num = long.Parse(array[3]) * 16777216L;

            num += (long)(int.Parse(array[2]) * 65536);
            num += (long)(int.Parse(array[1]) * 256);
            return(num + (long)int.Parse(array[0]));
        }
Ejemplo n.º 11
0
        public static string GetServerDomain()
        {
            string text = HttpContext.Current.Request.Url.Host.ToLower();

            if (text.Split('.').Length < 3 || Validate.IsIP(text))
            {
                return(text);
            }
            string text2 = text.Remove(0, text.IndexOf(".") + 1);

            if (text2.StartsWith("com.") || text2.StartsWith("net.") || text2.StartsWith("org.") || text2.StartsWith("gov."))
            {
                return(text);
            }
            return(text2);
        }