Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Given an IP address and subnetmask, how do I calculate the CIDR?

Ok I can't seem to figure this out: given the following:

IP address = 192.168.1.0
Subnetmask = 255.255.255.240

Using c#, how do I calculate the CIDR notation 192.168.1.0/28 ? Is there an easy way to achieve this? Am I missing something?

Thanks!

like image 624
RoelF Avatar asked Mar 24 '10 13:03

RoelF


1 Answers

256 - 240 = 16 = 2**4, 32 - 4 = 28

It is not really a C# question.

To get a net address from an IP and mask you can apply bytewise and to the IP and mask. You can get bytes from a string using IPAddress.Parse() and IPAddress.GetAddressBytes().

like image 66
wRAR Avatar answered Nov 15 '22 03:11

wRAR