Administrator IP address matching method

Source: Internet
Author: User
1   //  Final Method  2   3   4   5           Public   Static   Bool Getadminloginip ( String  Loginip)  6   {  7 List <mastermodel> List = Null ;  8 List = (list <mastermodel> ) Utility. makecacheall [common. Constraints. c_adminuserloginip];  9               If (List! = Null  )  10   {  11                   Foreach (Mastermodel Model In  List)  12  {  13                       If (Model. Name = "  *.*.*.*  " ) //  Allow all IP addresses  14   {  15                           Return   True  ;  16   } 17                       Else   If (Model. Name = loginip) //  Allow the current IP address to exist.  18   {  19                           Return   True  ;  20   }  21                       Else   // Start matching IP Address  22   {  23                           Int Flag = 0 ; //  The default value is 0 when the number of successful matches starts.  24                           String [] Loginiparray = loginip. Split ( '  .  ' ); //  Logon IP Address  25                          String [] Strip = model. Name. Split ( '  .  ' ); //  Allow IP  26                           For ( Int I = 0 ; I < 4 ; I ++ )  27   {  28                              If (Strip [I]! = "  *  "  )  29   {  30                                   If (Strip [I] = Loginiparray [I])  31   {  32 Flag + = 1 ; // If the IP address segment matches successfully, the number of matches increases by 1.  33   }  34                                   Else  35   {  36 Flag = 0 ; //  The number of matching failures is 0 and the current loop exists.  37                                       Break  ;  38  }  39   }  40                               Else  41   {  42 Flag + = 1 ; //  * The number of successful matches + 1 by default  43   }  44  }  45                           If (Flag = 4 ) //  Matched  46   {  47                               Return   True  ;  48   }  49                           // Else  50                           //  {  51                           //  Continue;  //  Jump out of the current loop and perform the next loop  52                           //  }  53   }  54   }  55                  Return   False  ;  56   }  57               Return   False  ;  58 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.