CFLib.org – Common Function Library Project

IpInRange(start, end, ip)

Last updated March 4, 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);
	}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson