IPConvert(ip or numeric version)
Last updated August 28, 2003
Version: 1 | Requires: ColdFusion 5 | Library: NetLib
Description:
IPConvert converts valid IP addresses into integers and back again. This is useful for storing IP information in a database using the int datatype rather than char.
Return Values:
Returns either a number of an IP.
Example:
<cfset ip=IPConvert(int)>
<cfoutput>
Converted to: #int#<br>
Converted back to: #ip#
</cfoutput>
Parameters:
| Name | Description | Required |
|---|---|---|
| ip or numeric version | IP or numeric version of IP. | Yes |
Full UDF Source:
<cfscript>
/**
* Converts IPs to integers and back for efficient database storage.
*
* @param ip or numeric version IP or numeric version of IP. (Required)
* @return Returns either a number of an IP.
* @author Aaron Eisenberger (aaron@x-clothing.com)
* @version 1, August 28, 2003
*/
function IPConvert(val) {
var int = '';
var ip = arraynew(1);
if (find('.',val))
{
int = 0;
int = ListGetAt(val, 1, ".") * 256^3;
int = int + ListGetAt(val, 2, ".") * 256^2;
int = int + ListGetAt(val, 3, ".") * 256;
int = int + ListGetAt(val, 4, ".");
return int;
}
else
{
int = val;
ip[1] = Int(int / 256^3);
int = int - (ip[1] * 256^3);
ip[2] = int(int / 256^2);
int = int - (ip[2] * 256^2);
ip[3] = int(int / 256);
ip[4] = int - (ip[3] * 256);
ip = ip[1] & "." & ip[2] & "." & ip[3] & "." & ip[4];
return ip;
}
}
</cfscript>
Search CFLib.org
Latest Additions
Tayo Akinmade added
arrayTrim
10 day(s) ago
Will Belden added
longTime
15 day(s) ago
James Sleeman added
quickSort
25 day(s) ago
Ben Forta added
GetHostAddress
28 day(s) ago
Top Rated
EksporSQLData
Rated 5.0, 16 time(s)
backupDatabase
Rated 5.0, 13 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)