its pretty simple to do a whois query. simply use sockets to connect to the various whois servers for each tld.
here's an example for .com, .net, .org domains using network solutions.
$fp = fsockopen("whois.networksolutions.com", 43, $errno, $errstr, 30);
if(!$fp) {
echo "Couldn't connect to whois server. Try again later.";
exit;
}
fputs($fp, "domainname.com\r\n");
while(!feof($fp)) {
echo fgets($fp, 255);
}
fclose($fp);
of course you will have to come up with a list of whois servers for all the different tld's. but you can easily do that by issuing a similar command in the socket. connect to sipb.mit.edu and just put whois-servers instead of the domain, and it will return a list of all whois servers and the tld's they look up. also, if you use network solutions to look up a domain registered with tucows, it will say looking up info from tucows, so you may want to search the data for that so you can issue another whois to the referral server and get the most accurate information.