C#版ip2long和long2ip

public static long ip2long(string ipAddress) 
{
    try

    {
       System.Net.IPAddress ip = System.Net.IPAddress.Parse(ipAddress); 
       return (((long)ip.GetAddressBytes()[0] < < 24) | ((int)ip.GetAddressBytes()[1] << 16) | ((int)ip.GetAddressBytes()[2] << 8) | ip.GetAddressBytes()[3]); 
    }
    catch (Exception) 
    {
        return 0; 
    }
}

public static string long2ip(long ipAddress) 
{
    try

    {
        System.Net.IPAddress tmpIp = System.Net.IPAddress.Parse(ipAddress.ToString()); 
        Byte[] bytes = tmpIp.GetAddressBytes();   
        long addr = (long)BitConverter.ToInt32(bytes, 0);
        return new System.Net.IPAddress(addr).ToString(); 
    }
    catch (Exception e) { return e.Message; } 
}