using System;
using System.Net;
class App
{
static long ToInt(string addr)
{
// careful of sign extension: convert to uint first;
// unsigned NetworkToHostOrder ought to be provided.
return (long) (uint) IPAddress.NetworkToHostOrder(
(int) IPAddress.Parse(addr).Address);
}
static string ToAddr(long address)
{
return IPAddress.Parse(address.ToString()).ToString();
// This also works:
// return new IPAddress((uint) IPAddress.HostToNetworkOrder(
// (int) address)).ToString();
}
static void Main()
{
//假设
www.plcxue.com服务器ip地址为:64.233.187.99,换后的结果为1089059683
Console.WriteLine(ToInt("64.233.187.99"));
//1089059683转换后的结果为:64.233.187.99
Console.WriteLine(ToAddr(1089059683));
}
}