I want to get client subnet mask using c#.
How can I get it?
The network ID is found by logically ANDing the binary form of the IP address with the binary form of the subnet mask for the network. For example, if a host has an IP address of 172.16. 8.55 on a network with a subnet mask of 255.255. 0.0 (the default subnet mask), the network ID of the host is 172.16.
To calculate the IP Address Subnet you need to perform a bit-wise AND operation (1+1=1, 1+0 or 0+1 =0, 0+0=0) on the host IP address and subnet mask. The result is the subnet address in which the host is situated.
First of all, check NetworkInterface
class first. There are a lot of information in it. And these articles will be helpful for you:
IP Address Calculations with C# (Subnetmasks, Networks, …)
Get Subnet Mask
Finding subnet mask from IP4 address using c#
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With