• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 923
  • Last Modified:

compare single ip to ip range

I want to allow access to a certain folder based on IP address. I can get the IP address from user and check it and all that good stuff.
The problem is I have a table that holds 2 values, starting IP and ending IP, the majority of these are ranges, not single IP's.   How can I check the single IP I get programatically against the table of IP ranges to authenticate a user?
0
flukester
Asked:
flukester
  • 2
  • 2
1 Solution
 
jmwheelerCommented:
I think you can do a simple string comparison (it sounded too simple but I couldn't come up with a reason why it wouldn't work).

ipLow
ipHigh
userIP

if (ipLow.CompareTo(userIP) <= 0 And ipHigh.CompareTo(userIP) >= 0) then ....
0
 
flukesterAuthor Commented:
Thanks jmw, seems to be working so far. Can you enlighten me to what the CompareTo() method is actually doing? How is it finding an IP if it's in a range.
0
 
jmwheelerCommented:
CompareTo is a comparison method for objects that implement IComparable.  It returns less than zero if the instance is less than the passed obj, 0 if they are the same and greater than zero if the instance is greater than the passed obj.

http://msdn.microsoft.com/en-us/library/system.icomparable.compareto.aspx
0
 
flukesterAuthor Commented:
Thanks a lot!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now