IP和数字相互转换函数
留着备份~
public static String Ip2Number(String ip)
{
String[] segs = ip.split("\\.");
long value = 0;
for (int index = 0; index < segs.length; ++index)
{
value += Long.valueOf(segs[index]) << (24 - index *8);
}
return value + "";
}
public static String Number2Ip(String num)
{
long value = Long.valueOf(num);
String ip = "";
for (int index = 0;; ++index)
{
ip = ip + (value >> 24);
value = (value - (value >> 24 << 24)) << 8;
if (index >= 3)
{
break;
}
ip = ip + ".";
}
return ip;
}