Answer the question
In order to leave comments, you need to log in
How to count the number of combinations in an ip range?
There is such a range - 217.28.250.232 - 217.28.252.215
1) 217.28.250.232 - 217.28.252.255 = 23
2) 217.28.251.0 - 217.28.252.255 = 255 3) 217.28.252.0 -
217.252.215
= 215
in the amount of 493 in the amount of
On paper, it doesn't seem difficult. But what formula would you use for this? 0_o
Answer the question
In order to leave comments, you need to log in
In JS: (language was not specified here)
const ip2int = (ip) =>
ip.split('.')
.map( (value, index) => Number(value) * 256 ** (3-index))
.reduce( (sum,value) => sum + value, 0);
const range = (from, to) => ip2int(to) - ip2int(from);
console.log(range("192.168.1.0", "192.168.1.255"));
// 255 - т.е. броадкаст адрес он тоже считает
Formula from your paper. Or is the formula in one line important to you?
Although, you also want to calculate the sum of the ranges, perhaps arbitrary (without a mask), where already there in one line.
In general, if there is an algorithm, then you can make a calculator. And whether there will be 10 lines of code or 200 is not so important.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question