我需要解析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),并且在上面的命令中没有它的位置。
发布于 2013-11-14 19:00:18
使用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发布于 2013-11-14 19:08:06
这就是答案:
$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";
}
?>https://stackoverflow.com/questions/19975861
复制相似问题