How to check a input IP fall in a specific IP range
asp.net, c#
Solution
reposting my answer from here
A while ago, I had to find the location of a given IP. We got the IP from the request. There are free databases which gave us this mapping. In IPv4, when we say the IP as "a.b.c.d" it is essentially `a * (256^3) + b * (256^2) + c * (256) + d`.
http://www.aboutmyip.com/AboutMyXApp/IP2Integer.jsp
so when you say you want an IP address starting with "a", you are looking for IPs between a * 256^ 3 and a * 256^3 + 256 * (256^2) (b = 256) + 256 *(256) (c=256) + 256( d=256) (lower / upper limit may vary a little bit depending on whether you want to include/exclude the limits).
That said, there are specific IPs reserved for specific purposes(like 127.0.0.1 which is localhost, 0.0.0.0 cannot be an IP etc).
So your linq query would be
from i in iList where i >= MIN && i <= MAX select i;
where iList is your initial list MIN is your min value for your range MAX is your max value for your range
Problem
If we let users input a couple of ip ranges, e.g., 172.16.11.5 - 100, how could I write a function to check if a IP (172.16.11.50) falls in the ranges? Is there any existing library in .NET to leverage?