获得IP的ULong值

2014-06-15 14:21:11  访问(4779) 赞(0) 踩(0)

  • 
    
            #region 获得IP的Long值
    
            /// 
            /// 获得IP的Long值
            /// 
            /// 
            /// 
            public static ulong IpToULong(string ip)
            {
                if (ip == null || ip.Length == 0)
                    throw new Exception("ip == null || ip.Length == 0");
    
                ip = ip.Trim();
    
                if (ip.Length == 0)
                    throw new Exception("ip.Trim().Length == 0");
    
                string[] strIpArray = ip.Split('.');
    
                if (strIpArray == null || strIpArray.Length != 4)
                    throw new Exception("string ip[" + ip + "] 为无效IP");
     
                return ulong.Parse(strIpArray[0])
                    * 256 * 256 * 256
                    + ulong.Parse(strIpArray[1])
                    * 256 * 256
                    + ulong.Parse(strIpArray[2])
                    * 256
                    + ulong.Parse(strIpArray[3]) - 1;
            }
    
            #endregion 获得IP的Long值
    
    
    

  • IP地址:
    输出:

标签:获得IP的ULong值    转换ip地址值    C#代码    IP地址操作 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)
 
  ┈全部┈  
 
(显示默认分类)