CFLib.org – Common Function Library Project

ip2long(ip)

Last updated January 9, 2009

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

 
Rated 1 time(s). Average Rating: 5.0

Description:
Converts a string containing an (IPv4) Internet Protocol dotted address (aaa.bbb.ccc.ddd) into a proper address representation. Returns 0 if error occurs.

Return Values:
Returns a number.

Example:

view plain print about
<cfoutput>
#ip2long('202.186.13.4')#= 3401190660<br>
</cfoutput>

Parameters:

Name Description Required
ip IP address as string. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * Converts a string containing an (IPv4) Internet Protocol dotted address (aaa.bbb.ccc.ddd) into a proper address representation.
 * 
 * @param ip      IP address as string. (Required)
 * @return Returns a number. 
 * @author Troy Pullis (tpullis@yahoo.com) 
 * @version 0, January 9, 2009 
 */

function ip2long(ip) {
    var iparr = ListToArray(ip,".");
    if (ArrayLen(iparr) != 4)
        return 0;
    else 
         return iparr[1]*256^3 + iparr[2]*256^2 + iparr[3]*256 + iparr[4];
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Adam Cameron Adam Cameron added
composeDateTime
16 day(s) ago

Chris Weller Chris Weller added
convertQueryStri...
a while ago

Greg Nettles Greg Nettles added
arrayDiff
a while ago

Nathan Dintenfass Nathan Dintenfass added
ArrayOfStructsSo...
a while ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 36 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Rachel Lehman deAccent
Rated 5.0, 6 time(s)

Isaac Dealey                                      countArbitraryDa...
Rated 5.0, 5 time(s)

Created by Raymond Camden / Design by Justin Johnson