Copy link to clipboard
Copied
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
1 Correct answer
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
...Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
I suggest passing Adam's question to the collegue who said you need the subnet mask.
Copy link to clipboard
Copied
Dan Bracuk wrote:
I suggest passing Adam's question to the collegue who said you need the subnet mask.
Yup.
--
Adam
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thanks for your relies.
BKBK - thanks very much just what I was after

