• IP格式检查、IP INT 转换


     public static bool CheckIPAddress(string IP)
            {
                
    string pattern = @"(((\d{1,2})|(1\d{2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{2})|(2[0-4]\d)|(25[0-5]))";
                System.Text.RegularExpressions.Regex regex 
    = new System.Text.RegularExpressions.Regex(pattern);
                
    if (regex.Match(IP).Success)
                {
                    
    return true;
                }
                
    else
                {
                    
    return false;
                }
            }

            
    private static long IpToInt(string ip)
            {
                
    char[] separator = new char[] { '.' };
                
    if (ip.Split(separator).Length == 3)
                {
                    ip 
    = ip + ".0";
                }
                
    string[] strArray = ip.Split(separator);
                
    long num2 = ((long.Parse(strArray[0]) * 0x100L* 0x100L* 0x100L;
                
    long num3 = (long.Parse(strArray[1]) * 0x100L* 0x100L;
                
    long num4 = long.Parse(strArray[2]) * 0x100L;
                
    long num5 = long.Parse(strArray[3]);
                
    return (((num2 + num3) + num4) + num5);
            }

            
    private static string IntToIP(long ip_Int)
            {
                
    long num = (long)((ip_Int & 0xff000000L>> 0x18);
                
    if (num < 0L)
                {
                    num 
    += 0x100L;
                }
                
    long num2 = (ip_Int & 0xff0000L>> 0x10;
                
    if (num2 < 0L)
                {
                    num2 
    += 0x100L;
                }
                
    long num3 = (ip_Int & 0xff00L>> 8;
                
    if (num3 < 0L)
                {
                    num3 
    += 0x100L;
                }
                
    long num4 = ip_Int & 0xffL;
                
    if (num4 < 0L)
                {
                    num4 
    += 0x100L;
                }
                
    return (num.ToString() + "." + num2.ToString() + "." + num3.ToString() + "." + num4.ToString());
            }
  • 相关阅读:
    Luogu P2495 [SDOI2011]消耗战
    40. Combination Sum II
    39. Combination Sum
    22. Generate Parentheses
    51. N-Queens
    Codeforces Round #346 (Div. 2) E. New Reform
    Codeforces Round #346 (Div. 2) D. Bicycle Race
    HDU 5651xiaoxin juju needs help
    VK Cup 2016
    Educational Codeforces Round 10 D. Nested Segments
  • 原文地址:https://www.cnblogs.com/RobotTech/p/944053.html
Copyright © 2020-2023  润新知