0

我需要解析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"

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

4

2 回答 2

0

使用 nslookup 代替更简单的输出,每个 ip 都有 Address: 在前面,所以很容易正则表达式

[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
于 2013-11-14T11:00:18.243 回答
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";
   }
?>
于 2013-11-14T11:08:05.833 回答