<?php
// DESIGN
define("TITLE", "WhoIs");
define("ALIGN", "left");

//FUNCTION WHOIS
function whois($url, $ip)
{
$sock = @fsockopen($url, 43, $errno, $errstr);

	if(!$sock)
	{
	exit("$errno($errstr)");
	}
	else
	{
	fwrite($sock, $ip."\r\n");
	$text = "";
	while(!feof($sock))
	{
		$text .= fgets($sock, 128);
	}
	fclose($sock);

		if(preg_match("#ReferralServer: whois://([a-z]+\.[a-z]+\.[a-z]+)#i", $text, $out))
		{
		return whois($out[1], $ip);
		}
		else
		{
		$text = htmlspecialchars($text);
		$text = str_replace("\n\n\n", "\n", $text);
		$text = str_replace("\n", "<br />\n", $text);
		return $text;
		}
	}
}

?>