Blog   About   Contact

WHOIS your Daddy?

I was playing around with querying a whois server. Actually I didn't know it was that easy...

Here's the code:


<cffunction name="getWhoisData" access="public" returntype="string" hint="I return data from a whois server">
    <cfargument name="whoisQuery" type="string" required="true" hint="e.g. 'domain microsoft' or '?' to show whois server help-commands">
    <cfargument name="whoisServer" type="string" required="false" hint="e.g. whois.ripe.net. Default server is whois.internic.net">

    <cfscript>
        var whoisData = '';
        var whoisClient = createObject("java","org.apache.commons.net.WhoisClient");
        
        // use default whois server?
        if ( not isDefined("arguments.whoisServer") ){
            arguments.whoisServer = whoisClient.DEFAULT_HOST;
        }    
        
        try {
            whoisClient.connect(arguments.whoisServer);
            whoisData = whoisClient.query(arguments.whoisQuery);
            whoisClient.disconnect();
        } catch (Any exception) {
            whoisData = exception.message;
        }

        return whoisData;
    
</cfscript>
</cffunction>

Some examples:


<cfoutput>
    <h1>? [whois.internic.net]</h1>
    <pre>#getWhoisData('?')#</pre>    
    <h1>domain microsoft.com [whois.internic.net]</h1>
    <pre>#getWhoisData('domain microsoft.com')#</pre>
    <h1>=microsoft.com [whois.internic.net]</h1>
    <pre>#getWhoisData('=microsoft.com')#</pre>    
    <h1>registrar TUCOWS INC. [whois.internic.net]</h1>
    <pre>#getWhoisData('registrar TUCOWS INC.')#</pre>    
    <h1>-G -B 192.113.224.88 [whois.ripe.net]</h1>
    <pre>#getWhoisData('-G -B 192.113.224.88','whois.ripe.net')#</pre>    
</cfoutput>

Comments
Ben Nadel's Gravatar That's pretty slick. I love when stuff is built into Java for you :)
# Posted By Ben Nadel | 2/9/09 1:52 AM
Ernst van der Linden's Gravatar Yip, hidden jar-gems... :-)
# Posted By Ernst van der Linden | 2/9/09 1:56 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.004.