Java examples for Network:Network Address
get String Of Sub Network Address Ranges
//package com.java2s; import java.util.ArrayList; import java.util.List; public class Main { public static List<String> getStringOfSubNetworkAddressRanges( byte[][] addressRange) { List<String> addressRangeList = new ArrayList<String>(); for (int i = 0; i < addressRange[0].length; i++) { if (i == 0) { addressRangeList.add(byteToString(addressRange[0][i]) + "-" + byteToString(addressRange[1][i])); } else { for (int j = 0; j < addressRangeList.size(); j++) { addressRangeList.set(j, "." + addressRangeList.get(j)); }/*from www . j a v a 2 s. co m*/ if (addressRange[0][i] == addressRange[1][i]) { for (int j = 0; j < addressRangeList.size(); j++) { addressRangeList.set(j, byteToString(addressRange[0][i]) + addressRangeList.get(j)); } } else { int mapAddNumber = addressRange[1][i] - addressRange[0][i]; int addressRangeListSize = addressRangeList.size(); for (int j = 0; j < addressRangeListSize; j++) { String address = addressRangeList.get(j); addressRangeList.set(j, byteToString(addressRange[0][i]) + address); for (int k = 1; k <= mapAddNumber; k++) { addressRangeList .add(byteToString((byte) (addressRange[0][i] + k)) + address); } } } } } return addressRangeList; } public static String byteToString(byte b) { return Integer.toString(b & 0xff); } }