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

Restricting a page based on IP range

New Here ,
Nov 10, 2009 Nov 10, 2009

Hello,

CF newb here. I know how to restrict access to a page based on individual IPs using:

<cfif TRUE AND CGI.REMOTE_ADDR NEQ '123.45.67.80'
AND #cgi.remote_addr# NEQ '123.45.67.81
AND #cgi.remote_addr# NEQ '123.45.67.84'>

But I need to restrict access to a page to just allowing people in my local IP range to see it. Is there a way of excluding all IP except for those in, say, 123.45.67.80 through 123.45.67.99 without having to key in all of them individually?

Thanks a lot!!

4.0K
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 ,
Nov 10, 2009 Nov 10, 2009

if (left(cgi.remote_addr, 9) is "123.45.67"

and right(cgi.remote_addr, 2) gte 80

and right(cgi.remote_addr, 2) lte 99)

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
Valorous Hero ,
Nov 10, 2009 Nov 10, 2009

You might also want to look at the IP address as a dot {.} deliminited list and see what you can do with the list functions.

http://livedocs.adobe.com/coldfusion/8/htmldocs/functions-pt0_13.html

Also, you may want to think outside of the reactor (my ColdFusion metaphore for a box).  And see about what you can do within the Web Server.  All the major web servers have the ability to restrict requests to specific content to specific IP addresses or address ranges.

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
New Here ,
Nov 10, 2009 Nov 10, 2009

<cfset ipaddress = cgi.remote_addr>

<cfset classa = listgetat(ipaddress,1,".")>

<cfset classb = listgetat(ipaddress,2,".")>

<cfset classc = listgetat(ipaddress,3,".")>

<cfset classd = listgetat(ipaddress,4,".")>

<cfif classa eq 123 and classb eq 45 and classc eq 67 and classd lte 99 and classd gte 80>

     <!--- whatever you want to do --->

</cfif>

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
New Here ,
Nov 10, 2009 Nov 10, 2009

Thanks a lot, guys! Much appreciated. I believe I was able to do it via IIS by excluding all IP except for our local range, but the CF snippets will come in very handy, too.

Cheers!

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
Enthusiast ,
Nov 10, 2009 Nov 10, 2009

convert start & end of IP range to decimal, then simply check if the IP is

within that range (this is how the db based geolocators work).

<cfscript>

function ipNumber(ipAddress) {

var a=listFirst(arguments.ipAddress,".");

var b=listGetAt(arguments.ipAddress,2,".");

var c=listGetAt(arguments.ipAddress,3,".");

var d=listLast(arguments.ipAddress,".");

return (a * 16777216) + (b * 65536) + (c * 256) + d;

}

</cfscript

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
Advocate ,
Nov 10, 2009 Nov 10, 2009

Hi Scotch123,

I think this UDF might help you to acheive that.

http://cflib.org/udf/isIPInRange

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 Beginner ,
Aug 16, 2019 Aug 16, 2019

This is an really old question, but since it was not answered.

In Lucee you can just use isIPinRange() https://docs.lucee.org/reference/functions/isipinrange.html

https://docs.lucee.org/reference/functions/isipinrange.html

I don't know if this is available in the Adobe version of Coldfusion yet.

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 ,
Aug 16, 2019 Aug 16, 2019

XIntelligence  wrote

I don't know if this is available in the Adobe version of Coldfusion yet.

It may never be added to ACF.  The Adobe programmers aren't exactly known for considering what us devs want/need.

V/r,

^ _ ^

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 ,
Aug 16, 2019 Aug 16, 2019

Wolf, why the snarkiness ? I do love how often you are able to help folks here so often, but why not leave it at that? Why the occasional jabs?

At least strive to be accurate, rather than fall into the "fake news" trap. There are PLENTY of ways that the CF team has responded to developer wants and needs, with EVERY update and EVERY new version to CF. Do they do everything everyone wants? No. But that's true of all tech (including Lucee).

But back to the original question, no, CF currently does not offer a function like that discussed above. There are many things in Lucee that are not in CF, just like there are many things in CF that are not in Lucee. Each team decides (and demand from their user base influences) what features are worth adding--and both sometimes add what the other had added, even without demand, if it's deemed simple and useful enough.

But as for those seeking this function, if you do want it in CF, you can file a feature request at tracker.adobe.com. And yes, the CF team really does respond to those. No, again, not EVERY request or bug, but MANY with each update and new version. Really.


/Charlie (troubleshooter, carehart. org)
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 ,
Aug 16, 2019 Aug 16, 2019

https://forums.adobe.com/people/Charlie+Arehart  wrote

Wolf, why the snarkiness ? I do love how often you are able to help folks here so often, but why not leave it at that? Why the occasional jabs?

Charlie, I consider myself to be a ColdFusion acolyte, but not specifically an Adobe CF acolyte.  Granted, ACF is what we use, as well as at every other job where I've worked, but that's because every place I've worked refuses to give Lucee a chance, for various reasons.

And, yes, I am very vocally critical of Adobe, which is part of the reason why I have turned down every request I've received to be an ACP.  Yeah, I'd feel like kind of a hypocrite if I did take it.  But from a few interactions that I've had with the staff who monitor the bug tracker / feature requester, very few things have ever been corrected, despite votes and other users commenting in my favour, OR that of others' (this isn't all about me).

The rest have been met with what I consider to be substandard responses.  From things like marking my request or report as a duplicate of another that was submitted after mine; to specious work-avoidance justifications, as another user called it; to "we are not fixing this because it is 'as designed'" arguments; to half-arsed attempts at fixing something that (in this day and age) can be considered a security risk, at least for those whom prefer pseudonyms vs real name as online identity.

So, yes, admittedly I can be a bit snarky, as you put it, but I do honestly feel that it's justified.  And I'm not the only one.

And as far as helping folks, absolutely.  I should give back at least what I get.  And I have received a lot, over the years, from so many folks like you, and osgood_, and Nancy O'Shea, and Birnou, and the rest too many to mention, here.  Plus, I just love helping people.  Especially with things like RegEx, arrays/structs, and the like.

But this is O/T.  Apologies to OP for hijacking this thread.  Stepping down so that assistance can be provided by others more familiar with OPs request.

V/r,

^ _ ^

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 ,
Aug 16, 2019 Aug 16, 2019

Understood. And I realize you may no longer be looking at this thread, and we should avoid hijacking it.

But first I want to repeat what I'd said above about filing bugs (as if anticipating your response):

"...yes, the CF team really does respond to those. No, again, not EVERY request or bug, but MANY with each update and new version. Really."

As for mine, I do lament is when people take their personal experience and make assertions that could lead readers to think it applies to everyone. By that I mean that it can't POSSIBLY be true that "very few things have ever been corrected, despite votes and other users commenting in my favour, OR that of others'." There are sometimes dozens of bug fixes in each update, and they come out about every 4-6 months. That can be hundreds per year. Clearly they ARE fixing bugs and adding feature requests.

That said, I realize you draw your conclusion "from a few interactions that I've had with the staff who monitor the bug tracker / feature requester".  But then you add about your derision that you're "not the only one" to hold it. I get it: some want to hate on Adobe for various reasons. And I don't deny that dismay is sometimes surely warranted. 🙂

But from my observation, much is not; instead it often reflects negative sterotypes perpetuated (most often) by people who have long ago left CF but still scream out their past frustrations. Or any of us can fall into the trap about some particular issue, if we may have "given up" on it, even when evidence to the contrary can be offered. I made a similar point just today about CFB, in another thread today--that Wolf and I coincidentally happened to reply to at the exact same time, with again different perspectives. 🙂

That said, Wolf and I rarely come to loggerheads, and I do appreciate the help he (and others) offer here. I guess I just didn't realize we stood on "different side of the aisle" so much, on some matters at least. But hey, we can all help keep each other honest, whether in the help we offer, the assertions we make, or in the aspersions we cast. 🙂 I'm open to correction when I may err, of course.


/Charlie (troubleshooter, carehart. org)
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 ,
Aug 16, 2019 Aug 16, 2019
LATEST

"I am very vocally critical of Adobe, which is part of the reason why I have turned down every request I've received to be an ACP."

As a potential fellow ACP, I'd ask you to maybe reconsider. You don't have to be an advocate for the product, just someone who helps. You help a lot, and I think having that logo next to your name would be a good guide for people asking for help. That's all Adobe needs here.

Dave Watts, Eidolon LLC

Dave Watts, Eidolon LLC
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