PHP get DNS Nameserver, Cname, MX, A records d'un domaine – BinaryTides – Bien choisir son serveur d impression
PHP a une fonction utile appelée dns_get_record qui permet d’obtenir très facilement différents types d’enregistrements pour un domaine donné.
Nameserver – NS Records:
$ php -a
Shell interactif
php> print_r (dns_get_record ('www.binarytides.com', DNS_NS));
Tableau
(
[0] => Tableau
(
[host] => binarytides.com
[type] => NS
[target] => omikro1.allwebserver.com
[class] => IN
[ttl] => 86140
)
[1] => Tableau
(
[host] => binarytides.com
[type] => NS
[target] => omikro2.allwebserver.com
[class] => IN
[ttl] => 86140
)
)
php>
Un enregistrement – adresse IP:
php> print_r (dns_get_record ('www.binarytides.com', DNS_A));
Tableau
(
[0] => Tableau
(
[host] => binarytides.com
[type] => A
[ip] => 64.131.72.23
[class] => IN
[ttl] => 14046
)
)
php>
Une autre méthode simple pour obtenir l’enregistrement A ou l’adresse IP d’un nom de domaine consiste à utiliser la fonction gethostbyname:
php> print_r (gethostbyname ('www.binarytides.com'));
64.131.72.23
php>
Une autre méthode, gethostbynamel, donnerait un tableau d'adresses IP:
php> print_r (gethostbynamel ('www.google.com'));
Tableau
(
[0] => 74.125.71.147
[1] => 74.125.71.99
[2] => 74.125.71.104
[3] => 74.125.71.106
[4] => 74.125.71.105
[5] => 74.125.71.103
)
php>
Enregistrement MX – Serveur mail:
Les enregistrements MX donnent le serveur de messagerie pour un domaine donné. Ces serveurs de messagerie peuvent être utilisés pour envoyer des courriers à un certain courrier sur ce domaine, par exemple. [email protected]
php> print_r (dns_get_record ('www.binarytides.com', DNS_MX));
Tableau
(
[0] => Tableau
(
[host] => binarytides.com
[type] => MX
[pri] => 0
[target] => binarytides.com
[class] => IN
[ttl] => 14400
)
)
php>
Pour les enregistrements MX, il existe une fonction alternative appelée getmxrr, qui peut être utilisée comme ceci:
php> getmxrr ('www.binarytides.com', $ mxhosts);
php> print_r ($ mxhosts);
Tableau
(
[0] => binarytides.com
)
php>
Il retourne un tableau de mxhosts pour un nom d'hôte / domaine donné.
CNAME Records – Alias Canonical:
php> print_r (dns_get_record ('www.binarytides.com', DNS_CNAME));
Tableau
(
[0] => Tableau
(
[host] => www.binarytides.com
[type] => CNAME
[target] => binarytides.com
[class] => IN
[ttl] => 13932
)
)
php>
Avec l'option DNS_ALL, vous pouvez obtenir toutes les informations ci-dessus en même temps:
php> print_r (dns_get_record ('www.binarytides.com', DNS_ALL));
Tableau
(
[0] => Tableau
(
[host] => binarytides.com
[type] => A
[ip] => 64.131.72.23
[class] => IN
[ttl] => 14202
)
[1] => Tableau
(
[host] => binarytides.com
[type] => NS
[target] => omikro2.allwebserver.com
[class] => IN
[ttl] => 86344
)
[2] => Tableau
(
[host] => binarytides.com
[type] => NS
[target] => omikro1.allwebserver.com
[class] => IN
[ttl] => 86344
)
[3] => Tableau
(
[host] => www.binarytides.com
[type] => CNAME
[target] => binarytides.com
[class] => IN
[ttl] => 13800
)
[4] => Tableau
(
[host] => binarytides.com
[type] => SOA
[mname] => host1.allwebserver.com
[rname] => omikrosys.gmail.com
[serial] => 2011020202
[refresh] => 86400
[retry] => 7200
[expire] => 3600000
[minimum-ttl] => 86400
[class] => IN
[ttl] => 86344
)
[5] => Tableau
(
[host] => binarytides.com
[type] => MX
[pri] => 0
[target] => binarytides.com
[class] => IN
[ttl] => 14199
)
)
php>
Les autres options disponibles sont:
DNS_HINFO, DNS_PTR, DNS_SOA, DNS_TXT, DNS_AAAA, DNS_SRV, DNS_NAPTR, DNS_A6, DNS_ANY.
Références :
1. Manuel sur: http://php.net/manual/en/function.dns-get-record.php
Dernière mise à jour le: 27 mai 2013







Commentaires
Laisser un commentaire