サンプルコード
dns_get_recordを使ってホストに関連するDNSリソースレコードを取得します
<?php
//IPv4アドレスリソースレコードを取得
var_dump(dns_get_record('google.co.jp', DNS_A));
//エイリアス(Canonical Name)リソースレコードを取得
var_dump(dns_get_record('google.co.jp', DNS_CNAME));
//Mail Exchangerリソースレコードを取得
var_dump(dns_get_record('google.co.jp', DNS_MX));
//Authoritative Name Serverリソースレコードを取得
var_dump(dns_get_record('google.co.jp', DNS_NS));
//テキストリソースレコードを取得
var_dump(dns_get_record('google.co.jp', DNS_TXT));
//IPv6アドレスリソースレコードを取得
var_dump(dns_get_record('google.co.jp', DNS_AAAA));
?>
//IPv4アドレスリソースレコードを取得
array(1) {
[0]=>
array(5) {
["host"]=>
string(12) "google.co.jp"
["class"]=>
string(2) "IN"
["ttl"]=>
int(300)
["type"]=>
string(1) "A"
["ip"]=>
string(14) "216.58.196.227"
}
}
//エイリアス(Canonical Name)リソースレコードを取得
bool(false)
//Mail Exchangerリソースレコードを取得
array(5) {
[0]=>
array(6) {
["host"]=>
string(12) "google.co.jp"
["class"]=>
string(2) "IN"
["ttl"]=>
int(600)
["type"]=>
string(2) "MX"
["pri"]=>
int(10)
["target"]=>
string(18) "aspmx.l.google.com"
}
[1]=>
array(6) {
["host"]=>
string(12) "google.co.jp"
["class"]=>
string(2) "IN"
["ttl"]=>
int(600)
["type"]=>
string(2) "MX"
["pri"]=>
int(30)
["target"]=>
string(23) "alt2.aspmx.l.google.com"
}
[2]=>
array(6) {
["host"]=>
string(12) "google.co.jp"
["class"]=>
string(2) "IN"
["ttl"]=>
int(600)
["type"]=>
string(2) "MX"
["pri"]=>
int(50)
["target"]=>
string(23) "alt4.aspmx.l.google.com"
}
[3]=>
array(6) {
["host"]=>
string(12) "google.co.jp"
["class"]=>
string(2) "IN"
["ttl"]=>
int(600)
["type"]=>
string(2) "MX"
["pri"]=>
int(20)
["target"]=>
string(23) "alt1.aspmx.l.google.com"
}
[4]=>
array(6) {
["host"]=>
string(12) "google.co.jp"
["class"]=>
string(2) "IN"
["ttl"]=>
int(600)
["type"]=>
string(2) "MX"
["pri"]=>
int(40)
["target"]=>
string(23) "alt3.aspmx.l.google.com"
}
}
//Authoritative Name Serverリソースレコードを取得
array(4) {
[0]=>
array(5) {
["host"]=>
string(12) "google.co.jp"
["class"]=>
string(2) "IN"
["ttl"]=>
int(49943)
["type"]=>
string(2) "NS"
["target"]=>
string(14) "ns3.google.com"
}
[1]=>
array(5) {
["host"]=>
string(12) "google.co.jp"
["class"]=>
string(2) "IN"
["ttl"]=>
int(49943)
["type"]=>
string(2) "NS"
["target"]=>
string(14) "ns4.google.com"
}
[2]=>
array(5) {
["host"]=>
string(12) "google.co.jp"
["class"]=>
string(2) "IN"
["ttl"]=>
int(49943)
["type"]=>
string(2) "NS"
["target"]=>
string(14) "ns1.google.com"
}
[3]=>
array(5) {
["host"]=>
string(12) "google.co.jp"
["class"]=>
string(2) "IN"
["ttl"]=>
int(49943)
["type"]=>
string(2) "NS"
["target"]=>
string(14) "ns2.google.com"
}
}
//テキストリソースレコードを取得
array(1) {
[0]=>
array(6) {
["host"]=>
string(12) "google.co.jp"
["class"]=>
string(2) "IN"
["ttl"]=>
int(300)
["type"]=>
string(3) "TXT"
["txt"]=>
string(11) "v=spf1 -all"
["entries"]=>
array(1) {
[0]=>
string(11) "v=spf1 -all"
}
}
}
//IPv6アドレスリソースレコードを取得
array(1) {
[0]=>
array(5) {
["host"]=>
string(12) "google.co.jp"
["class"]=>
string(2) "IN"
["ttl"]=>
int(300)
["type"]=>
string(4) "AAAA"
["ipv6"]=>
string(24) "2404:6800:400a:808::2003"
}
}