CFLib.org – Common Function Library Project

getAllHostAddresses(host)

Last updated September 22, 2005

author

David Chaplin-Loebell

Version: 1 | Requires: CF5 | 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:

/**
 * 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;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson