<cfdump var="#getUnusedIPs('192.29.22.2,192.29.22.6','192.29.22.0','192.29.22.10')#">
<cffunction name="getUnusedIPs" returntype="array"> <cfargument name="ipList" type="string" required="true"/> <cfargument name="rangeStart" type="string" required="true"/> <cfargument name="rangeEnd" type="string" required="true"/> <cfscript> var startDec = ipToDecimalValue(rangeStart); var endDec = ipToDecimalValue(rangeEnd); var ipStruct = StructNew(); var ipSectionSize = 2^8; var ipVal = ""; var i = 0; var j = 0; var unusedIPs = ArrayNew(1); var ipAddr = ""; var tmpVal = ""; var tmpHex = ""; // Find All used IP Addresses for( i = 1; i lte #ListLen(ipList)#; i = i + 1 ) { ipVal = ipToDecimalValue(ListGetAt(ipList,i)); ipStruct[ipVal] = true; } for( i = startDec; i lte endDec; i = i + 1 ) { if( not StructKeyExists(ipStruct,i) ) { ipAddr = ""; tmpVal = i; for( j = 3; j gte 0; j = j -1 ) { tmpHex = int(tmpVal/ipSectionSize^j); tmpVal = tmpVal - tmpHex*ipSectionSize^j; ipAddr = ListAppend(ipAddr, tmpHex, "."); } ArrayAppend(unusedIPs,ipAddr); } } return unusedIPs; </cfscript> </cffunction> <cffunction name="ipToDecimalValue" returntype="numeric"> <cfargument name="ipAddr" type="string" required="true"/> <cfscript> var ipDecVal = 0; var ipSectionSize = 2^8; var tmpIPVal = 0; var i = 0; for( i = 1; i lte 4; i = i + 1 ) { tmpIPVal = ListGetAt(ipAddr,i,"."); ipDecVal = ipDecVal + tmpIPVal*ipSectionSize^(4-i); } return ipDecVal; </cfscript> </cffunction> <cffunction name="isWithinRange" returntype="boolean"> <cfargument name="ipAddr" type="string" required="true"/> <cfargument name="rangeStart" type="string" required="true"/> <cfargument name="rangeEnd" type="string" required="true"/> <cfset var ipDec = ipToDecimalValue(ipAddr)/> <cfreturn ipDec gte ipToDecimalValue(rangeStart) and ipDec lte ipToDecimalValue(rangeEnd)/> </cffunction> On 11/6/07, Todd <[EMAIL PROTECTED]> wrote: > 192.29.22 <http://192.29.22.0/> is constant. 0 to 225 is not. > > Make an array? append 0->225 on the end of 192.29.22 and then do your > checks/show the list of what's available? > > ~Todd > > On Nov 5, 2007 9:44 AM, Ben Nadel <[EMAIL PROTECTED]> wrote: > > > Robert, > > > > I don't know how to do this offhand, but you can convert IP addresses to > > a single big integer number. What you could do is figure out the start > > IP and end IP numbers, then do a simple FOR loop. For each loop > > iteration, you could take that number and convert it back to an IP > > address and check it. Not 100% how that would work, but maybe this can > > point you in a good direction. > > > > ...................... > > Ben Nadel > > Certified Advanced ColdFusion MX7 Developer > > www.bennadel.com > > > > Need ColdFusion Help? > > www.bennadel.com/ask-ben/ > > > > -----Original Message----- > > From: Orlini, Robert [mailto:[EMAIL PROTECTED] > > Sent: Monday, November 05, 2007 9:14 AM > > To: CF-Talk > > Subject: list help > > > > I would like to create a list of IP addresses, let's say, 192.29.22.0 to > > 192.29.22.255 and then with the list of IPs I already have of valid > > users in the same range, search through and find ones that don't match > > the range. > > > > For example, I would like the code to search through 192.29.22.0 to > > 192.29.22.255 and match IPs I have within this range and then list out > > IPs that are not there. If I have IP 192.29.22.122 in my list it should > > find a match within the range and do nothing, but if my list does not > > have IP 192.29.22.100 then it should flag this IP as available. > > > > Is there an easy way to do this without typing in the whole 192.29.22.0 > > to 192.29.22.255 range? Do I use a list function? > > > > Thanks. > > > > Robert O. > > HWW > > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Download the latest ColdFusion 8 utilities including Report Builder, plug-ins for Eclipse and Dreamweaver updates. http;//www.adobe.com/cfusion/entitlement/index.cfm?e=labs%5adobecf8%5Fbeta Archive: http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:292657 Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4