CFLib.org – Common Function Library Project

IPclass(ip)

Last updated February 14, 2004

author

del usr

Version: 1 | Requires: CF5 | Library: NetLib

Description:
Converts an IP address to a network class.

Return Values:
Returns a string.

Example:

<cfset varip = "192.168.0.1">
<cfset varclass = ipclass("192.168.0.1")>
<cfoutput>
    IP: #varip#<br />
    Class: #varclass#<br />
</cfoutput>

Parameters:

Name Description Required
ip IP address. Yes

Full UDF Source:

/**
 * Converts an IP address to a network class.
 * 
 * @param ip      IP address. (Required)
 * @return Returns a string. 
 * @author del usr (delusrexpert@hotmail.com) 
 * @version 1, February 14, 2004 
 */
function IPclass(ip) {
    var myint = listFirst(ip, ".");
    if (myint GTE 1 and myint LTE 127) return "Class A";
    if (myint GTE 128 and myint LTE 191) return "Class B";
    if (myint GTE 192 and myint LTE 223) return "Class C";
    if (myint GTE 224 and myint LTE 239) return "Class D";
    if (myint GTE 240 and myint LTE 255) return "Class 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