compare single ip to ip range

Posted on 2009-02-12
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?
Question by:flukester
    LVL 11

    Accepted Solution

    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).


    if (ipLow.CompareTo(userIP) <= 0 And ipHigh.CompareTo(userIP) >= 0) then ....

    Author Comment

    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.
    LVL 11

    Expert Comment

    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.

    Author Comment

    Thanks a lot!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now