Skip to main content
Inspiring
February 24, 2009
Answered

CGI.REMOTE_ADDR Range Question

  • February 24, 2009
  • 5 replies
  • 2162 views
I have a site that allows users to bypass a login screen and get direct access to my website depending on their IP address.

I have implemented quite a few of these without problem.

But now I have a client that has an IP range of 199.99.999.9/22 that I cant seem to get correct.

I have tried

CGI.REMOTE_ADDR CONTAINS '199.99.999.9' and Left(CGI.REMOTE_ADDR, 12)# EQ "199.99.999.9" to no avail.

Is the /22 the problem?

    This topic has been closed for replies.
    Correct answer Kronin555
    ah, OK. In that case, you want to allow:
    185.16.232.
    185.16.233.
    185.16.234.
    185.16.235.

    That should do what you want.

    LEFT(CGI.REMOTE_ADDR,11) EQ '185.16.232.' or LEFT(CGI.REMOTE_ADDR,11) EQ '185.16.233.' or
    LEFT(CGI.REMOTE_ADDR,11) EQ '185.16.234.' or
    LEFT(CGI.REMOTE_ADDR,11) EQ '185.16.235.'

    5 replies

    BKBK
    Community Expert
    Community Expert
    February 25, 2009
    Weezerboy wrote
    I wasnt using the actual one in the post but here it is now
    185.16.232.0/22

    How high do I go on the last 3 digits
    232,233,234,235,236,237....when do I stop?


    What you perhaps need to know is that the bits number /n in 185.16.232.0/n stands for the number of hosts. It means 2^(32-n) hosts. That is, 2 to the power 32 minus n hosts.

    In your case, n is 22. So your number of hosts is 2^(32-22). That is, 2^10, which evaluates to 1024. Hence Kronin's suggestion:

    185.16.232.0 - 185.16.232.255 (maximum 256 hosts)
    185.16.233.0 - 185.16.233.255
    185.16.234.0 - 185.16.234.255
    185.16.235.0 - 185.16.235.255



    Participating Frequently
    February 25, 2009
    And to expand on BKBK's explanation...
    "How did you get 232-235 for the 3rd octet?"
    The /22 actually is a bitmask. A full IPv4 address is 32 bits, in 4 octets. So, in binary, a /22 looks like:
    11111111 11111111 11111100 00000000
    That's your mask. Now take your starting IP address, which you posted as:
    185.16.232.0
    In binary, this looks like:
    10111001 00010000 11101000 00000000

    So if we focus on the 3rd octet, the netmask is:
    11111100
    and the network is:
    11101000

    So all the possible host values that fit in this network have a 3rd octet that look like:
    11101000 = 232
    11101001 = 233
    11101010 = 234
    11101011 = 235
    BKBK
    Community Expert
    Community Expert
    February 25, 2009
    [deleted]
    Kronin555Correct answer
    Participating Frequently
    February 24, 2009
    ah, OK. In that case, you want to allow:
    185.16.232.
    185.16.233.
    185.16.234.
    185.16.235.

    That should do what you want.

    LEFT(CGI.REMOTE_ADDR,11) EQ '185.16.232.' or LEFT(CGI.REMOTE_ADDR,11) EQ '185.16.233.' or
    LEFT(CGI.REMOTE_ADDR,11) EQ '185.16.234.' or
    LEFT(CGI.REMOTE_ADDR,11) EQ '185.16.235.'
    weezerboyAuthor
    Inspiring
    February 24, 2009
    How high do I go on the last 3 digits

    232,233,234,235,236,237....when do I stop?
    Participating Frequently
    February 24, 2009
    Just stop where I stopped. That's why I stopped :-)
    Participating Frequently
    February 24, 2009
    This is an invalid IP range:
    199.99.999.9/22

    It's not the /22 that's the problem (that just gives you the netmask). It's the 3rd octet. Nothing over 255 makes sense, and you have 999.

    Your netmask equates to 255.255.252.0.

    Double-check that IP range, then post back.
    weezerboyAuthor
    Inspiring
    February 24, 2009
    I wasnt using the actual one in the post but here it is now

    185.16.232.0/22
    Inspiring
    February 24, 2009
    weezerboy wrote:
    > I have a site that allows users to bypass a login screen and get direct access
    > to my website depending on their IP address.
    >
    > I have implemented quite a few of these without problem.
    >
    > But now I have a client that has an IP range of 199.99.999.9/22 that I cant
    > seem to get correct.
    >
    > I have tried
    >
    > CGI.REMOTE_ADDR CONTAINS '199.99.999.9' and Left(CGI.REMOTE_ADDR, 12)# EQ
    > "199.99.999.9" to no avail.
    >
    > Is the /22 the problem?
    >
    >
    >

    What does an IP rande of 199.99.999.9/22 mean? I would presume that it
    meant that the IP would fall some where in the range of 199.99.999.9 and
    199.99.99.22. If so, then you just need to test the different parts of
    the IP address (a list delineated by periods [.]) to see if the various
    elements match the expected criteria.