From 482a2aa5124d2cd1beab5a42e639bef1adfde45e Mon Sep 17 00:00:00 2001 From: sparc Date: Sun, 7 Sep 2008 09:00:12 +0000 Subject: [PATCH] also check for network nserver --- src/whois.client.php | 50 ++++++++++++++++++++++++++++++++++++++ src/whois.ip.php | 10 ++++++++ src/whois.main.php | 58 +++++--------------------------------------- src/whois.utils.php | 28 +++++++++++++-------- 4 files changed, 84 insertions(+), 62 deletions(-) diff --git a/src/whois.client.php b/src/whois.client.php index 76e1f10..3434284 100755 --- a/src/whois.client.php +++ b/src/whois.client.php @@ -527,4 +527,54 @@ class WhoisClient { return $a1; } + + function FixNameServer($nserver) + { + $dns = array(); + + foreach($nserver as $val) + { + $val = str_replace( array('[',']','(',')'), '', trim($val)); + $val = str_replace("\t", ' ', $val); + $parts = explode(' ', $val); + $host = ''; + $ip = ''; + + foreach($parts as $p) + { + if (substr($p,-1) == '.') $p = substr($p,0,-1); + + if ((ip2long($p) == - 1) or (ip2long($p) === false)) + { + // Hostname ? + if ($host == '' && preg_match('/^[\w\-]+(\.[\w\-]+)+$/',$p)) + { + $host = $p; + } + } + else + // IP Address + $ip = $p; + } + + // Valid host name ? + + if ($host == '') continue; + + // Get ip address + + if ($ip == '') + { + $ip = gethostbyname($host); + if ($ip == $host) $ip = '(DOES NOT EXIST)'; + } + + if (substr($host,-1,1) == '.') $host = substr($host,0,-1); + + $dns[strtolower($host)] = $ip; + } + + return $dns; + } + } diff --git a/src/whois.ip.php b/src/whois.ip.php index bcb4f0e..1f6680e 100644 --- a/src/whois.ip.php +++ b/src/whois.ip.php @@ -336,6 +336,16 @@ class ip_handler extends WhoisClient else $result['regyinfo']['type'] = 'ip'; + if (isset($result['regrinfo']['network']['nserver'])) + { + if (!is_array($result['regrinfo']['network']['nserver'])) + { + unset($result['regrinfo']['network']['nserver']); + } + else + $result['regrinfo']['network']['nserver'] = $this->FixNameServer($result['regrinfo']['network']['nserver']); + } + return $result; } diff --git a/src/whois.main.php b/src/whois.main.php index 779dbae..d2fc67e 100755 --- a/src/whois.main.php +++ b/src/whois.main.php @@ -266,7 +266,6 @@ class Whois extends WhoisClient */ function FixResult(&$result, $domain) { - // Add usual fields $result['regrinfo']['domain']['name'] = $domain; @@ -285,62 +284,17 @@ class Whois extends WhoisClient $result['regrinfo']['registered'] = 'unknown'; } - if (!isset($result['regrinfo']['domain']['nserver'])) return; - // Normalize nameserver fields - $nserver = $result['regrinfo']['domain']['nserver']; - - if (!is_array($result['regrinfo']['domain']['nserver'])) + + if (isset($result['regrinfo']['domain']['nserver'])) { - unset($result['regrinfo']['domain']['nserver']); - return ; - } - - $dns = array(); - - foreach($nserver as $val) - { - $val = str_replace( array('[',']','(',')'), '', trim($val)); - $val = str_replace("\t", ' ', $val); - $parts = explode(' ', $val); - $host = ''; - $ip = ''; - - foreach($parts as $p) + if (!is_array($result['regrinfo']['domain']['nserver'])) { - if (substr($p,-1) == '.') $p = substr($p,0,-1); - - if ((ip2long($p) == - 1) or (ip2long($p) === false)) - { - // Hostname ? - if ($host == '' && preg_match('/^[\w\-]+(\.[\w\-]+)+$/',$p)) - { - $host = $p; - } - } - else - // IP Address - $ip = $p; + unset($result['regrinfo']['domain']['nserver']); } - - // Valid host name ? - - if ($host == '') continue; - - // Get ip address - - if ($ip == '') - { - $ip = gethostbyname($host); - if ($ip == $host) $ip = '(DOES NOT EXIST)'; - } - - if (substr($host,-1,1) == '.') $host = substr($host,0,-1); - - $dns[strtolower($host)] = $ip; + else + $result['regrinfo']['domain']['nserver'] = $this->FixNameServer($result['regrinfo']['domain']['nserver']); } - - $result['regrinfo']['domain']['nserver'] = $dns; } } diff --git a/src/whois.utils.php b/src/whois.utils.php index 38091ae..fa81b3d 100755 --- a/src/whois.utils.php +++ b/src/whois.utils.php @@ -172,20 +172,28 @@ class utils extends Whois { $link = $_SERVER['PHP_SELF'].'?'.$params; $out = preg_replace ($ip_regex, '$0', $out); - + if (isset($result['regrinfo']['domain']['nserver'])) { $nserver = $result['regrinfo']['domain']['nserver']; - - if (is_array($nserver)) + } + else + $nserver = false; + + if (isset($result['regrinfo']['network']['nserver'])) + { + $nserver = $result['regrinfo']['network']['nserver']; + } + + if (is_array($nserver)) + { + print_r($nserver); + reset($nserver); + while (list($host, $ip) = each($nserver)) { - reset($nserver); - while (list($host, $ip) = each($nserver)) - { - $url = '$host"; - $out = str_replace($host, $url, $out); - $out = str_replace(strtoupper($host), $url, $out); - } + $url = '$host"; + $out = str_replace($host, $url, $out); + $out = str_replace(strtoupper($host), $url, $out); } } }