How should I correctly store IP address list with addresses which are subnets to make it searchable?
There are two examples:
-
I have IP address 1.2.3.4 and in my C# List there is 1.2.3.4 entry so here we have no problems.
-
I have IP address 3.4.5.6 and in my C# List I have subnet 3.4.0.0/24. Here is my problem.
How to store IP subnet in List to cover second example?
At the end of this answer you will find a complete implementation of a structure to represent a IPV4 address.
Here is really simple example of usage:-
The value “3.4.0.0/255.255.255.0” is displayed inthe console since 3.4.0.6 is found in the 3.4.0.0/24 subnet. Assuming
listis full of various subnets andxcould contain any address then this:-will select the most specific subnet for that contains
x.