Which .NET class should be used to represent the subnet and its mask?

I can use System.Net.IPAddressto represent a single IP address, but what can I use to represent an entire subnet, including a network address and a subnet mask?

+3
source share
2 answers

I believe that you can use System.Net.IPAddress to also represent the subnet mask. This is the same form, and the only real operation you need to perform is a bitmask based on bytes of the subnet address.

System.Net.IPAddress i = System.Net.IPAddress.TryParse("10.10.1.1");
Byte[] b = i.GetAddressBytes();
+2
source
struct NetworkIPAddress
{
  public IPAddress IP;
  public uint Mask;
}
+1
source

Source: https://habr.com/ru/post/1710682/


All Articles