<?php
//to get nameserver information
function get_name_servers ($domain)
{
$lookup_server = 'whois.nic.uk';
$result = array();
$port = 43;
$timeout = 10;
$fp_con = @fsockopen($lookup_server, $port, $errno, $errstr, $timeout) or die("Socket Error " . $errno . " - " . $errstr);
@fputs($fp_con, $domain."\r\n");
while (!@feof ($fp_con))
{
$str_buffer = fgets($fp_con);
if (ereg ('Name servers', $str_buffer))
{
$dns = fgets ($fp_con, 128);
$dns = str_replace ('Name Server:', '', $dns);
$dns = str_replace ('Server:', '', $dns);
$result['ns1'] = trim ($dns);
$dns = fgets ($fp_con, 128);
$dns = str_replace ('Name Server:', '', $dns);
$dns = str_replace ('Server:', '', $dns);
$result['ns2'] = trim ($dns);
$dns = fgets ($fp_con, 128);
$dns = str_replace ('Name Server:', '', $dns);
$dns = str_replace ('Server:', '', $dns);
$result['ns3'] = trim ($dns);
$dns = fgets ($fp_con, 128);
$dns = str_replace ('Name Server:', '', $dns);
$dns = str_replace ('Server:', '', $dns);
if (strpos ($dns, 'WHOIS lookup') == true)
{
$dns = '';
}
$result['ns4'] = trim ($dns);
continue;
}
}
$result['error'] = $error;
return $result;
}
$arr_ns = get_name_servers("google.co.uk");
print_r($arr_ns);
?>