Skip to main content
Inspiring
October 20, 2009
Answered

get IP address and subnet mask?

  • October 20, 2009
  • 2 replies
  • 2228 views

HI Folks,

Could anyone tell me how to determine if a users IP is with a certain IP range?

I need to determine if a user has a ip of 111.222.333.444, and a subnet mask of 444.555.666.777.

I can find out ho to get the ip address from the cgi variables, but not sure how the subnet mask works.

Can anyone please explain?

Thanks in advance

    This topic has been closed for replies.
    Correct answer BKBK

    Hi Matthisco,

    Your IT colleague is right. Your question is legitimate. There is indeed a formula for finding the range of IP addresses that corresponds to a given subnet.

    However, your question is more appropriate for a forum on networks than for a Coldfusion forum, for the calculations are quite involved. First, you must know whether the network is Class A (IPs of the form 10.x.x.x), Class B (IPs of form 172.x.x.x) or Class C (192.x.x.x). Other parameters you have to factor into the equation are the number of subnets, the number of subnet bits and the number of mask bits.

    To learn more, search the web for subnet mask. In fact,  there are online subnet calculators that generate IP ranges. You may then use such a range in your code.

    2 replies

    BKBK
    BKBKCorrect answer
    Community Expert
    October 24, 2009

    Hi Matthisco,

    Your IT colleague is right. Your question is legitimate. There is indeed a formula for finding the range of IP addresses that corresponds to a given subnet.

    However, your question is more appropriate for a forum on networks than for a Coldfusion forum, for the calculations are quite involved. First, you must know whether the network is Class A (IPs of the form 10.x.x.x), Class B (IPs of form 172.x.x.x) or Class C (192.x.x.x). Other parameters you have to factor into the equation are the number of subnets, the number of subnet bits and the number of mask bits.

    To learn more, search the web for subnet mask. In fact,  there are online subnet calculators that generate IP ranges. You may then use such a range in your code.

    matthiscoAuthor
    Inspiring
    October 27, 2009

    Thanks for your relies.

    BKBK - thanks very much just what I was after

    Inspiring
    October 22, 2009

    You can't reverse engineer a subnet mask from an IP address: there's not a one-to-one relationship between the two.

    How come you need to know what the client's subnet mask is?

    --

    Adam

    matthiscoAuthor
    Inspiring
    October 22, 2009

    Hi Adam,

    Thanks for your reply.

    I'm trying to redirect users depending upon their IP.

    My IT colleague told me to look for an IP address range in between:

    123.123.2.1 and the subnet mask 555.555.555.5

    I'm not sure how to do that with CF, I must of misunderstood him. I know how to get the IP using the CGI variables, but that it.

    Could you help at all?

    Thanks again

    Inspiring
    October 22, 2009

    I suggest passing Adam's question to the collegue who said you need the subnet mask.