CFLib.org – Common Function Library Project

IPclass(ip)

Last updated February 14, 2004
Download UDF

author

del usr                                           del usr

Version: 1 | Requires: ColdFusion 5 | Library: NetLib

 
Rated 0 time(s). Average Rating: 0

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:

<cfscript>
/**
* 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";
}
</cfscript>

Search CFLib.org


Latest Additions

Alan McCollough Alan McCollough added
forceBoolean
1 day(s) ago

Shawn Porter Shawn Porter added
DeMoronize
4 day(s) ago

Chris Carey Chris Carey added
readPropertiesFi...
5 day(s) ago

Randy Johnson Randy Johnson added
lastDayofWeek
7 day(s) ago

Top Rated

James Sleeman                                     QuickSort
Rated 5.0, 3 time(s)

Barney Boisvert indentXml
Rated 5.0, 3 time(s)

Nathan Dintenfass                                 queryColumnsToSt...
Rated 5.0, 3 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 3 time(s)

Created by Raymond Camden / Design by Justin Johnson