Код: Выделить всё
public static List getIPsInCIDR(String cidrRange) {
List ips = new ArrayList();
try {
// Split the CIDR range into IP and prefix length
String[] parts = cidrRange.split("/");
String ip = parts[0];
int prefix = Integer.parseInt(parts[1]);
// Calculate the number of addresses in the range
int numAddresses = (int) Math.pow(2, (32 - prefix));
// Convert the IP address to a byte array
byte[] ipBytes = InetAddress.getByName(ip).getAddress();
// Convert the byte array to an integer
int ipAddress = 0;
for (byte b : ipBytes) {
ipAddress = (ipAddress = 0; j--) {
currentIPBytes[j] = (byte) (currentIP & 0xFF);
currentIP >>= 8;
}
// Create InetAddress object from the byte array
InetAddress address = InetAddress.getByAddress(currentIPBytes);
// Add IP address to the list
ips.add(address.getHostAddress());
}
} catch (UnknownHostException e) {
e.printStackTrace();
}
return ips;
}
Подробнее здесь: https://stackoverflow.com/questions/785 ... et-library