/** 把long类型的Ip转为一般Ip类型:xx.xx.xx.xx * * @param ip * @return */ public static String getIpFromLong(Long ip) { String s1 = String.valueOf((ip & 4278190080L) / 16777216L); String s2 = String.valueOf((ip & 16711680L) / 65536L); String s3 = String.valueOf((ip & 65280L) / 256L); String s4 = String.valueOf(ip & 255L); return s1 + "." + s2 + "." + s3 + "." + s4; } /** 把xx.xx.xx.xx类型的转为long类型的 * * @param ip * @return */ public static Long getIpFromString(String ip) { Long ipLong = 0L; String ipTemp = ip; ipLong = ipLong * 256 + Long.parseLong(ipTemp.substring(0, ipTemp.indexOf("."))); ipTemp = ipTemp.substring(ipTemp.indexOf(".") + 1, ipTemp.length()); ipLong = ipLong * 256 + Long.parseLong(ipTemp.substring(0, ipTemp.indexOf("."))); ipTemp = ipTemp.substring(ipTemp.indexOf(".") + 1, ipTemp.length()); ipLong = ipLong * 256 + Long.parseLong(ipTemp.substring(0, ipTemp.indexOf("."))); ipTemp = ipTemp.substring(ipTemp.indexOf(".") + 1, ipTemp.length()); ipLong = ipLong * 256 + Long.parseLong(ipTemp); return ipLong; }