CFLib.org – Common Function Library Project

IpInRange(start, end, ip)

Last updated March 04, 2010

author

A. Cole

Version: 0 | Requires: CF7 | Library: CFMLLib

Description:
determines if the ip is within the start and end range

Return Values:
Returns a boolean.

Example:

#isIpInRange("192.168.1.1", "192.168.1.255", "192.168.1.50")# in range<br>
#isIpInRange("192.168.1.1", "192.168.3.255", "192.168.2.50")# in range<br>
#isIpInRange("192.168.1.1", "192.168.1.255", "192.168.3.50")# not in range<br>

Parameters:

Name Description Required
start start IP range Yes
end end IP range Yes
ip IP to test if in range Yes

Full UDF Source:

/**
 * determine if IP is with in a range.
 * 04-mar-2010 renamed to IPinRange so as not to conflict w/existing UDF
 * 
 * @param start      start IP range (Required)
 * @param end      end IP range (Required)
 * @param ip      IP to test if in range (Required)
 * @return Returns a boolean. 
 * @author A. Cole (acole76@NOSPAMgmail.com) 
 * @version 0, March 4, 2010 
 */
function isIpInRange(start, end, ip)
    {
        var startArray = listtoarray(arguments.start, ".");
        var endArray = listtoarray(arguments.end, ".");
        var ipArray = listtoarray(arguments.ip, ".");
        var s = ((16777216 * startArray[1]) + (65536 * startArray[2]) + (256 * startArray[3]) + startArray[4]);
        var e = ((16777216 * endArray[1]) + (65536 * endArray[2]) + (256 * endArray[3]) + endArray[4]);
        var c = ((16777216 * ipArray[1]) + (65536 * ipArray[2]) + (256 * ipArray[3]) + ipArray[4]);
        
        return isvalid("range", c, s, e);
    }

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson