Common tools, no more introduction, on the code.
Converts the IP address in the 127.0.0.1 form to a decimal integer, where no error handling is done public static long Iptolong (String strIp) {long[] IP = new LONG[4];//Find the IP address word first The position of the string. int position1 = Strip.indexof ("."); int position2 = Strip.indexof (".", Position1 + 1); int position3 = Strip.indexof (".", Position2 + 1); Converts the string between each. To integral type ip[0] = Long.parselong (strip.substring (0, Position1)); IP[1] = Long.parselong (strip.substring (position1 + 1, position2)); IP[2] = Long.parselong (strip.substring (position2 + 1, position3)); IP[3] = Long.parselong (strip.substring (Position3 + 1)); Return (Ip[0] <<) + (Ip[1] <<) + (Ip[2] << 8) + ip[3]; Convert decimal integer form to 127.0.0.1 IP address public static String Longtoip (long Longip) {StringBuffer sb = new StringBuffer (""); Move directly to the right 24-bit sb.append (string.valueof (LONGIP >>> 24)); Sb.append ("."); will be high 8 position 0, then the right to move 16-bit sb.append (string.valueof (LONGIP & 0x00ffffff) >>> 16)); Sb.append ("."); will be high 16 position 0, then the right to move 8-bit sb.append (string.valueof (LONGIP & 0x0000ffff) >>> 8));Sb.append ("."); will be high 24 position 0 sb.append (string.valueof (LONGIP & 0x000000ff)); return sb.tostring (); }