hostname
主機名(hostname)應該是一個DNS解析生效的域名,例如“www.example.com”。
主機名也可以是通過對逆向解析域做DNS逆向域名解析而得到,
但是在大多數情況下gethostbyaddr()更加適合做逆向域名解析。
說明
array dns_get_record (string $hostname [,int $type = DNS_ANY [,array &$authns [,array &$addtl [,bool &$raw = false ]]]] )
參數
type
默認情況下,dns_get_record()將會搜索所有與hostname相關的記錄,可以通過設置type來限定查詢。
type的值可以是下面的其中的任何一個: DNS_A,DNS_CNAME,DNS_HINFO,DNS_MX,DNS_NS,DNS_PTR,DNS_SOA,
DNS_TXT,DNS_AAAA,DNS_SRV,DNS_NAPTR,DNS_A6,DNS_ALL或者DNS_ANY。
authns
以引用方式傳遞,如果寫了該參數,那麽將會得到該解析記錄的DNS服務器(Authoritative Name Servers)的信息。
addtl
以引用方式傳遞,如果填寫了該參數,將會得到其他所有的DNS解析記錄。
raw
在原生模式下,在進行額外的查詢的時候之前我們只執行請求的DNS類型,而不是循環查詢所有的類型。
例1
<?php
$result = dns_get_record("php.net");
print_r($result);
?>
以上例程的輸出類似於:
Array
(
[0] => Array
(
[host] => php.net
[type] => MX
[pri] => 5
[target] => pair2.php.net
[class] => IN
[ttl] => 6765
)
[1] => Array
(
[host] => php.net
[type] => A
[ip] => 64.246.30.37
[class] => IN
[ttl] => 8125
)
)
例2
由於我們經常會想獲取一個郵件服務器的對應的IP地址的MX記錄是否已經生效。
在使用dns_get_record()函數之後,addtl能夠返回一個相關的數組記錄,
authns參數則會返回授權服務器的列表信息。
<?php
/* Request "ANY" record for php.net,
and create $authns and $addtl arrays
containing list of name servers and
any additional records which go with
them */
$result = dns_get_record("php.net", DNS_ANY, $authns, $addtl);
echo "Result = ";
print_r($result);
echo "Auth NS = ";
print_r($authns);
echo "Additional = ";
print_r($addtl);
?>
以上例程的輸出類似於:
Result = Array
(
[0] => Array
(
[host] => php.net
[type] => MX
[pri] => 5
[target] => pair2.php.net
[class] => IN
[ttl] => 6765
)
[1] => Array
(
[host] => php.net
[type] => A
[ip] => 64.246.30.37
[class] => IN
[ttl] => 8125
)
)
Auth NS = Array
(
[0] => Array
(
[host] => php.net
[type] => NS
[target] => remote1.easydns.com
[class] => IN
[ttl] => 10722
)
[1] => Array
(
[host] => php.net
[type] => NS
[target] => remote2.easydns.com
[class] => IN
[ttl] => 10722
)
[2] => Array
(
[host] => php.net
[type] => NS
[target] => ns1.easydns.com
[class] => IN
[ttl] => 10722
)
[3] => Array
(
[host] => php.net
[type] => NS
[target] => ns2.easydns.com
[class] => IN
[ttl] => 10722
)
)
Additional = Array
(
[0] => Array
(
[host] => pair2.php.net
[type] => A
[ip] => 216.92.131.5
[class] => IN
[ttl] => 6766
)
[1] => Array
(
[host] => remote1.easydns.com
[type] => A
[ip] => 64.39.29.212
[class] => IN
[ttl] => 100384
)
[2] => Array
(
[host] => remote2.easydns.com
[type] => A
[ip] => 212.100.224.80
[class] => IN
[ttl] => 81241
)
[3] => Array
(
[host] => ns1.easydns.com
[type] => A
[ip] => 216.220.40.243
[class] => IN
[ttl] => 81241
)
[4] => Array
(
[host] => ns2.easydns.com
[type] => A
[ip] => 216.220.40.244
[class] => IN
[ttl] => 81241
)
)
留言列表