PHP DNS解析器

时间:2013-11-14 10:58:05

标签: php dns

我需要解决dns问题。 这是我的cmd命令:

host -a google.com 8.8.8.8

(host -a s4.artemisweb.jp ns0.domain_name.com
 host -a s4.artemisweb.jp 77.88.8.1)

并返回类似的内容:

root@min /etc # host -a google.com 8.8.8.8
Trying "google.com"
;; Truncated, retrying in TCP mode.
Trying "google.com"
Using domain server:
Name: 8.8.8.8
Address: 8.8.8.8#53
Aliases:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 6364
;; flags: qr rd ra; QUERY: 1, ANSWER: 24, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;google.com.                    IN      ANY

;; ANSWER SECTION:
google.com.             300     IN      A       74.125.232.103
google.com.             300     IN      A       74.125.232.96
google.com.             300     IN      A       74.125.232.102
google.com.             300     IN      A       74.125.232.97

我需要进一步的工作

74.125.232.103            74.125.232.96 etc. ip addresses.(answer section)

其实php有

$result = dns_get_record("php.net", DNS_ANY, $authns, $addtl);

但我也有第二个参数

"8.8.8.8" or "ns0.domain_name.com or 77.88.8.1"

(并使用此附加参数“host”命令返回不同的IP),并且在上面的命令中没有它的位置。

2 个答案:

答案 0 :(得分:0)

使用nslookup而不是简化输出,每个ip都有地址:在前面这么容易正则表达式

[root@sid ~]# nslookup www.google.com
Server:         10.0.0.253
Address:        10.0.0.253#53

Non-authoritative answer:
Name:   www.google.com
Address: 74.125.24.99
Name:   www.google.com
Address: 74.125.24.147
Name:   www.google.com
Address: 74.125.24.104
Name:   www.google.com
Address: 74.125.24.103
Name:   www.google.com
Address: 74.125.24.106
Name:   www.google.com
Address: 74.125.24.105

答案 1 :(得分:0)

以下是答案:     

$resolver = new Net_DNS_Resolver();
$resolver->debug = 1; // Turn on debugging output to show the query
$resolver->usevc = 1; // Force the use of TCP instead of UDP
$resolver->nameservers = array(              // Set the IP addresses
                           '198.41.0.4',     // of the nameservers
                           '192.228.79.201'  // to query.
                           );
   $response = $resolver->query('example.com');
   if (! $response) {
      echo "\n";
      echo "ANCOUNT is 0, therefore the query() 'failed'\n";
      echo "See Net_DNS_Resolver::rawQuery() to receive this packet\n";
   }
?>