下面是一段C#测试代码,可以将点分割的ip地址转换成长整形,也可以讲长整形转换成点分割的ip地址
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.75271.com服务器ip地址为:64.233.187.99,换后的结果为1089059683 Console.WriteLine(ToInt("64.233.187.99")); //1089059683转换后的结果为:64.233.187.99 Console.WriteLine(ToAddr(1089059683)); } }