Last active
December 15, 2015 03:39
-
-
Save jostyee/5196067 to your computer and use it in GitHub Desktop.
InetAddress hashCode to IP address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static String getIpStr(int ip) { | |
StringBuilder sb = new StringBuilder(); | |
int addr[] = new int[4]; | |
addr[0] = (ip>>24) & 0xff; | |
addr[1] = (ip>>16) & 0xff; | |
addr[2] = (ip>>8) & 0xff; | |
addr[3] = ip & 0xff; | |
for (int i = 0; i < addr.length; i++) { | |
sb.append(addr[i]); | |
if (i < addr.length - 1) { | |
sb.append("."); | |
} | |
} | |
//System.out.println(java.util.Arrays.toString(addr)); | |
return sb.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment