Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java convert ip to long

public long ipToLong(String ipAddress) {

	String[] ipAddressInArray = ipAddress.split(".");

	long result = 0;
	for (int i = 0; i < ipAddressInArray.length; i++) {

		int power = 3 - i;
		int ip = Integer.parseInt(ipAddressInArray[i]);
		result += ip * Math.pow(256, power);

	}

	return result;
  }
Source by mkyong.com #
 
PREVIOUS NEXT
Tagged: #java #convert #ip #long
ADD COMMENT
Topic
Name
6+3 =