– Common Function Library Project

isIPInRange(sIP, sIPREList)

Last updated April 14, 2005


Peter Crowley

Version: 1 | Requires: CF6 | Library: NetLib

Returns true if the passed IP address matchs any of the IP addresses or IP address ranges supplied in a Regex list. This code be to useful in blocking or granting people access based on location. I used it to block people running check/cheque scams from certain areas of the website. Must use comma delimited list.

Return Values:
Returns a boolean.


<CFSET blockedIPrange="^217\.78\.(6[4-9]|7[0-9])\.[0-9]+,^195\.166\.2(2[4-9]|[3-4][0-9]|5[0-5])\.[0-9]+">

<cfif isIPInRange(CGI.REMOTE_ADDR,blockedIPrange)>
This website is not available in your location.


Name Description Required
sIP The IP. Yes
sIPREList List of IP Regex strings. Yes

Full UDF Source:

 * Is this IP within any of the IP ranges supplied.
 * @param sIP      The IP. (Required)
 * @param sIPREList      List of IP Regex strings. (Required)
 * @return Returns a boolean. 
 * @author Peter Crowley ( 
 * @version 1, April 14, 2005 
function isIPInRange(sIP,sIPREList) {
    var i = 1;
    var nREListCount=ListLen(sIPREList);
    for (i = 1; i LTE nREListCount; i = i+1) {
        if (REFind(ListGetAt(sIPREList,i),sIP)) return true;
    return false;


Latest Additions

Raymond Camden added
November 04, 2017

Leigh added
May 11, 2016

Raymond Camden added
May 10, 2016

Kevin Cotton added
May 05, 2016

Raymond Camden added
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson