question about subnetmask
is there any method in C# to which i pass ip address and subnetmask and it return true if given ip is in subnet mask?
For example, i give ip 192.168.0.149 and subnetmask 192.168.0.0 to the funtion and it return true................... Is there some thing like this in C#
Re: question about subnetmask
If you have the IP (v4) address stored in a long....
Code:
bool match = (addr & mask) == mask;
If you have it in a byte array..
Code:
bool match = (addr[0] & mask[0]) == mask[0]) &&
(addr[1] & mask[1]) == mask[1]) &&
(addr[2] & mask[2]) == mask[2]) &&
(addr[3] & mask[3]) == mask[3]);
If you have it in a string.... DONT! Change your design. :p