获得IP的Long值 - IpToULong
2017-02-26 15:19:32 访问(1437) 赞(0) 踩(0)
#region 获得IP的Long值
/// <summary>
/// 获得IP的Long值 - IpToULong
/// </summary>
/// <param name="ip"></param>
/// <returns></returns>
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的Long值 - IpToULong 


上一条:
下一条:
相关评论
发表评论