CFLib.org – Common Function Library Project

getAllHostAddresses(host)

Last updated September 22, 2005

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

 
Rated 0 time(s). Average Rating: 0

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:

view plain print about
<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:

view plain print about
<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>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
11 day(s) ago

Will Belden Will Belden added
longTime
17 day(s) ago

James Sleeman James Sleeman added
quickSort
27 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
30 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

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

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson