CFLib.org – Common Function Library Project

IPAddress2IPDottedDecimal([ipAddress])

Last updated September 27, 2002
Download UDF

author

Jonathan Pickard                                  Jonathan Pickard

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

 
Rated 0 time(s). Average Rating: 0

Description:
Use IPAddress2IPDottedDecimal to convert an IP address string to a decimal value. Storing decimal values in a database and making comparisons with them is more efficient than using IP address strings.

Return Values:
Returns a number.

Example:

<cfoutput>
#IPAddress2IPDottedDecimal( "192.168.0.7" )#
</cfoutput>

Parameters:

Name Description Required
ipAddress IP Address to convert. No

Full UDF Source:

<cfscript>
/**
* Converts an IP address to a 32-bit dotted decimal IP number.
*
* @param ipAddress      IP Address to convert. (Optional)
* @return Returns a number.
* @author Jonathan Pickard (j_pickard@hotmail.com)
* @version 1, September 27, 2002
*/

function IPAddress2IPDottedDecimal( ipAddress ) {
    var    ipValue = 0;
    var lBitShifts = "24,16,8,0";
    var i = 1;

    if ( ListLen( ipAddress, "." ) EQ 4 )
    {
        for ( ; i LTE 4; i = i + 1 )
        {
            ipValue = ipValue + BitSHLN( ListGetAt( ipAddress, i, "." ), ListGetAt( lBitShifts, i ) );
        }
    }

    return ipValue;
}
</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