Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

compare single ip to ip range

Posted on 2009-02-12
4
Medium Priority
?
921 Views
Last Modified: 2012-08-13
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
Comment
Question by:flukester
  • 2
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
jmwheeler earned 2000 total points
ID: 23622708
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
 

Author Comment

by:flukester
ID: 23626078
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
 
LVL 11

Expert Comment

by:jmwheeler
ID: 23626452
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
 

Author Comment

by:flukester
ID: 23626484
Thanks a lot!
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question