CFLib.org – Common Function Library Project

getAllHostAddresses(host)

Last updated September 22, 2005
Download UDF

author

David Chaplin-Loebell                             David Chaplin-Loebell

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

Description:
Performs an "A" record DNS lookup. Based on GetHostAddress() by Ben Forta. This version returns all A records for the host in an array. Good if you need need to get all host addresses for a host that uses round-robin DNS. (The comment in the original function refers to this as a "reverse lookup" but that is not actually correct DNS terminology-- this is a forward lookup.)

Return Values:
Returns an array.

Example:

<cfset addr = GetAllHostAddresses("www.yahoo.com")>
<cfloop list="#arraytolist(addr)#" index="ip">
<cfoutput>#ip#<br /></cfoutput>
</cfloop>

Parameters:

Name Description Required
host Host name. Yes

Full UDF Source:

<cfscript>
/**
* Looks up all IP addresses for a hostname and returns them in an array. Requires Java.
*
* @param host      Host name. (Required)
* @return Returns an array.
* @author David Chaplin-Loebell (davidcl@tlavideo.com)
* @version 1, September 22, 2005
*/

function getAllHostAddresses(host) {
    var iaclass=""; //holds the Java object
    var addr=""; //holds the array returned by the java object
    var hostaddr=arrayNew(1); //holds the returned array of IP addresses.
    var i = "";
    
    // Init class
    iaclass=CreateObject("java", "java.net.InetAddress");

    // Get address
    addr=iaclass.getAllByName(host);

    // Return the address
    for (i=1; i LTE ArrayLen(addr); i=i+1) {
        iaclass = Addr[i]; //can't access Addr[i].getHostAddress() directly in CF5
        hostaddr[i] = iaclass.getHostAddress();
    }
    return hostaddr;
}
</cfscript>

Search CFLib.org


Latest Additions

Raymond Compton Raymond Compton added
structBlend
19 day(s) ago

Duncan Duncan added
IsZIPUK
19 day(s) ago

Todd Sharp Todd Sharp added
getTagContentAll
25 day(s) ago

Gerald Guido Gerald Guido added
ListReturnDuplicat...
1 month(s) ago

Gerald Guido Gerald Guido added
ListReturnDuplicat...
1 month(s) ago

Created by Raymond Camden / Design by Justin Johnson