Welcome to Snipped, a code gallery for creating, saving and sharing all kinds of code snippets.

Who Is Domain Lookup Function

PHP · February 16, 2017 6:34 pm

0 0 96

Who Is Domain Lookup Function in PHP

<?php
function whiIsLookup($domain) {
if (!is_string($domain) || !preg_match('`^[a-z]{1,}([-\.][a-z]+)+$`i', $domain)) {
return false;
}

function query_server($domain, $server = 'whois.iana.org') {
$response = '';
if ($fsk = fsockopen($server, 43, $errno, $errstr, 2)) {
fputs($fsk, $domain . "\r\n");
while (!feof($fsk)) {
$response .= fgets($fsk, 1024);
}
@fclose($fsk);
}
if (preg_match('`^[\s]*whois[\s]*(?:server[\s]*)?:[\s]*([-a-z\.]+)[\s]*$`mi', $response, $m)) {
$server = $m[1];
return $server;
} else {
return $response;
}
}

$response_or_next_server = 'whois.iana.org';

$i = 5; // max 5 queries
while(preg_match('`^[-a-z\.]+$`', $response_or_next_server)) {
if ( !($i--) ) {
return null;
}
$response_or_next_server = query_server($domain, $response_or_next_server);
}

return $response_or_next_server;
}

echo '<pre>'.whiIsLookup('codecanyon.net').'</pre>';
?>

Discuss this Snip
    No Discussion Comments found.

    You must be Signed In to discuss this Snip
Snipped

Snipped

Joined on
February 16, 2017

  • 9 Snips
    Contributed
  • 0 Likes
    Given
  • 0 Comments Posted
Snip Tags
Get Social And Share

Manage and share all of your code snippets in one easy place.