Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

get IP address and subnet mask?

Explorer ,
Oct 20, 2009 Oct 20, 2009

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

2.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 24, 2009 Oct 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

...
Translate
LEGEND ,
Oct 22, 2009 Oct 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 22, 2009 Oct 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 22, 2009 Oct 22, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 22, 2009 Oct 22, 2009

Dan Bracuk wrote:

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

Yup.

--

Adam

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 24, 2009 Oct 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 27, 2009 Oct 27, 2009
LATEST

Thanks for your relies.

BKBK - thanks very much just what I was after

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources