DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Coldfusion Whois Component
A whois cfc for querying a whois client.
whois.cfc
<cfcomponent name="WhoIs" output="true">
<!--- the host to connect to --->
<cfset variables.server = "">
<!--- port on server to connect to --->
<cfset variables.port = "">
<!--- the whois query to run --->
<cfset variables.whoisQuery = "">
<!--- socket timeout in seconds --->
<cfset variables.connTimeout = 0>
<!--- the result of the server response --->
<cfset variables.response = "">
<cffunction name="init" access="public" returntype="WhoIs" hint="">
<cfargument name="server" type="string" default="whois.geektools.com"/>
<cfargument name="port" type="numeric" default="43"/>
<cfargument name="connTimeout" type="numeric" default="30" hint="Socket timeout in seconds"/>
<cfscript>
variables.server = arguments.server;
variables.port = JavaCast("int",arguments.port);
variables.connTimeout = (arguments.connTimeout * 1000);
//create before use variables.connection = createObject("java","java.net.Socket").init(variables.server,variables.port);
//dump(variables.connection,true); </cfscript>
<cfreturn this>
</cffunction>
<cffunction name="lookup" access="public" returntype="any" hint="">
<cfargument name="whoisQuery" type="string" required="true"/>
<cfset var line = "">
<cfset var eof = false>
<cfscript>
variables.whoisQuery = arguments.whoisQuery;
variables.connection.setSoTimeout(JavaCast("int",variables.connTimeout));
out = createObject("java","java.io.PrintStream").init(variables.connection.getOutputStream());
//send the query to the server out.println(variables.whoisQuery);
variables.response = variables.response & "Connection made to: " & "[" & variables.server & ":" & variables.port & "]";
instream = createObject("java","java.io.BufferedReader").init(createObject("java","java.io.InputStreamReader").init(variables.connection.getInputStream() ));
try {
//output results while(not eof) {
line = instream.readLine();
variables.response = variables.response & line & "#chr(10)#";
}
}
//coldfusion cant check for null so check for an UndefinedVariableException catch(coldfusion.runtime.UndefinedVariableException exception) {
eof = true;
}
catch(Any e){
writeOutput("Catch All Exception: " & e);
}
out.close();
instream.close();
variables.connection.close();
</cfscript>
<cfreturn variables.response>
</cffunction>
<cffunction name="dump" access="public" returntype="void" output="true" hint="">
<cfargument name="var" type="any" required="true"/>
<cfargument name="abort" type="boolean" default="false"/>
<cfdump var="#arguments.var#" label="#arguments.var#">
<cfif arguments.abort><cfabort></cfif>
</cffunction>
</cfcomponent>
index.cfm
<cfscript>
wi = createObject("component","WhoIs").init("whois.geektools.com",43,10);
results = wi.lookup("google.com");
writeOutput(htmlCodeFormat(results));
</cfscript>






Comments
Snippets Manager replied on Sat, 2010/05/08 - 4:00pm