IP Address Range Calculator

bleauhaus

New Member
Joined
Oct 3, 2014
Messages
2
Im sure this has been posted but after reading over this forum and others i still cannot find a solution.

Given the first two columns of IP addresses i want to generate the third or even fourth Column


StartIPEndIPTotal IPsTotal /24s
1.32.0.01.32.127.25532,766128
2.15.0.02.15.255.25565,534256
31.206.0.031.206.255.25565,534256
39.112.0.039.127.255.2551,048,5744096
42.16.0.042.47.255.2552,097,1508190
42.186.0.042.186.255.25565,534256
42.195.0.042.195.255.25565,534256
49.51.0.049.51.255.25565,534256
59.110.0.059.111.255.255131,070512
83.210.0.083.210.31.2558,19032
85.208.0.085.209.255.255131,070512
100.0.0.0100.41.255.2552,752,51210752
101.202.0.0101.202.255.25565,534256
104.141.0.0104.141.255.25565,534256

<tbody>
</tbody>
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Off the top of my head
0.0.0.0 if we work right to left 0 = 0 to 255, and then next is also the same (this you know)

so

dim n, dim m

for n = 0 to 255
for m = 0 to 255

next m
next n

should walk up those two values

obvioulsy you need to constrain n and m respectively

generating two million IPs will outstrip the available row space of Excel as demonstrated with 100.0.0.0

or did I miss the point
 
Upvote 0
Hi,

Not all of us are IP wizards :) So what's the logic for getting the values in column C and D, once we know that, we should be able to get a formula to do the work

A UDF like this might work but it gives a value 2 greater than what you have


Excel 2010
ABCD
1StartIPEndIPTotal IPsTotal /24s
21.32.0.01.32.127.25532768128
32.15.0.02.15.255.25565536256
431.206.0.031.206.255.25565536256
539.112.0.039.127.255.25510485764096
642.16.0.042.47.255.25520971528192
742.186.0.042.186.255.25565536256
842.195.0.042.195.255.25565536256
949.51.0.049.51.255.25565536256
1059.110.0.059.111.255.255131072512
1183.210.0.083.210.31.255819232
1285.208.0.085.209.255.255131072512
13100.0.0.0100.41.255.255275251210752
14101.202.0.0101.202.255.25565536256
15104.141.0.0104.141.255.25565536256
Sheet1
Cell Formulas
RangeFormula
C2=TotalIPs(A2,B2)
D2=C2/256


Code:
Function TotalIPs(C1 As Range, C2 As Range)
   Dim diff(), I As Integer
   TotalIPs = 1
   ReDim Preserve diff(0 To UBound(Split(C1, ".")))
   For I = LBound(Split(C1, ".")) To UBound(Split(C1, "."))
        TotalIPs = TotalIPs * (Split(C2, ".")(I) - Split(C1, ".")(I) + 1)
   Next I
   'TotalIPs = TotalIPs - 2
End Function
 
Last edited:
Upvote 0
Thanks Guys

As Momentman pointed out let me paint a little better picture... Looking at a single range and quickly determining its size (manually) such as



ABCD
1StartIPEndIPTotal IPsTotal /24s
21.32.0.01.32.127.25532768128

<colgroup><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>

only takes a second but you have to compare each of the four octets (the number between the dots) then calculate in your head the sum difference. its not a big deal with a single range but when your dealing with a column of ranges as in the original table A an B - trying to determine the largest or smallest can be an irritating task. with a hundred ranges it quickly becomes near impossible. check out The TCP/IP Guide - IP Classless Addressing Block Sizes and "Classful" Network Equivalents
 
Upvote 0
As Momentman pointed out let me paint a little better picture...
Well, you really didn't do that as Momentman asked for the logic of getting the values in columns C and D. All you told us on that front was "calculate in your head".



Sorry, but it is up to you to understand what is required and explain it to us, not for us to go researching a topic we know nothing about. :eek:


Going on what Momentman did with his udf, here's a formula solution that produces the same results. Not the results you quoted, but you haven't told us how to get those numbers. Subtracting 2 would do it but I don't know the logic for why you would do that.


Excel Workbook
ABC
1StartIPEndIPTotal IPs
21.32.0.01.32.127.25532,768
32.15.0.02.15.255.25565,536
431.206.0.031.206.255.25565,536
539.112.0.039.127.255.2551,048,576
642.16.0.042.47.255.2552,097,152
742.186.0.042.186.255.25565,536
842.195.0.042.195.255.25565,536
949.51.0.049.51.255.25565,536
1059.110.0.059.111.255.255131,072
1183.210.0.083.210.31.2558,192
1285.208.0.085.209.255.255131,072
13100.0.0.0100.41.255.2552,752,512
14101.202.0.0101.202.255.25565,536
15104.141.0.0104.141.255.25565,536
Sheet2
 
Upvote 0
1. Did you see the solution i posted above?

2. Should the answer to the first example be 32768 or 32766? and whats your formula for getting the values in column D?
 
Upvote 0
Here is another formula attempt:

Excel Workbook
ABCD
1StartIPEndIPTotal IPsTotal /24s
21.32.0.01.32.127.25532768128
32.15.0.02.15.255.25565536256
431.206.0.031.206.255.25565536256
539.112.0.039.127.255.25510485764096
642.16.0.042.47.255.25520971528192
742.186.0.042.186.255.25565536256
842.195.0.042.195.255.25565536256
949.51.0.049.51.255.25565536256
1059.110.0.059.111.255.255131072512
1183.210.0.083.210.31.255819232
1285.208.0.085.209.255.255131072512
13100.0.0.0100.41.255.255275251210752
14101.202.0.0101.202.255.25565536256
15104.141.0.0104.141.255.25565536256
Sheet2
 
Upvote 0
Is that correct? Change the last octet in A2 to 255.
 
Upvote 0
Is that correct? Change the last octet in A2 to 255.

I don't know to be honest, mine returns 256 - is that not correct?

Excel Workbook
N
32.15.0.255
42.15.1.255
52.15.etc.255
62.15.etc.255
72.15.254.255
82.15.255.255
Sheet1
 
Upvote 0
An IP address is an unsigned 32-bit number. The four octets (each 0 to 255) are the four bytes, high to low. So ...

The difference between x.y.z.1 and x.y.z.2 is 256^0 = 1

The difference between x.y.1.z and x.y.2.z is 256^1 = 256

The difference between x.1.y.z and x.1.y.z is 256^2 = 65536

The difference between 1.x.y.z and 2.x.y.z is 256^3 = 16777216
 
Upvote 0

Forum statistics

Threads
1,216,728
Messages
6,132,363
Members
449,720
Latest member
NJOO7

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top