checkdnsrr() - php 网络函数
checkdnsrr()
(PHP 4, PHP 5, PHP 7)
给指定的主机(域名)或者IP地址做DNS通信检查
说明
checkdnsrr(string $host[,string $type="MX"]): bool根据不同记录($type)类型查询主机($host)相应的DNS记录。
参数
$host主机($host)可以是一个IP地址也可以是域名。
$type解析记录类型($type)可能是下面这些类型中的任何一个:A,MX,NS,SOA,PTR,CNAME,AAAA,A6, SRV,NAPTR,TXT 或者 ANY。
返回值
如果记录能找到,就返回TRUE
;如果查找不到该DNS记录或者发生了错误,就返回FALSE
。
更新日志
版本 | 说明 |
---|---|
5.3.0 | 这个函数在Windows平台上也可以使用了。 |
5.2.4 | 增加了TXT的记录类型 。 |
5.0.0 | 增加了AAAA的记录类型 。 |
注释
Note:出于对低版本在windows平台上的兼容性,可以试试» PEAR扩展包里面提供的» Net_DNS类。
参见
dns_get_record()
获取指定主机的DNS记录getmxrr()
获取互联网主机名对应的 MX 记录gethostbyaddr()
获取指定的IP地址对应的主机名gethostbyname()
返回主机名对应的 IPv4地址。gethostbynamel()
获取互联网主机名对应的 IPv4 地址列表- the named(8) manual page
criffoh at gmail dot com is right. Before you check domain, you must convert to ascii with idn_to_ascii function: http://us2.php.net/manual/en/function.idn-to-ascii.php . var_dump(checkdnsrr('ñandu.cl', 'A')); // returns false var_dump(checkdnsrr(idn_to_ascii('ñandu.cl'), 'A')); // return true
Important Warning: You need to add a dot to the end of the host name to make a fully qualified domain name. To see why, try executing the following pieces of code: $d1="gmail.con"; $d2="gmail.con."; $r1=checkdnsrr($d1, "MX"); $r2=checkdnsrr($d2, "MX"); var_dump($r1); var_dump($r2); You will see that without the dot it claims that the domain "gmail.con" is valid. Note that if you time the "checkdnsrr()" calls you will also see it takes longer without the dot because it treats it as a relative domain and does several tries based on the host name it is running on. NB: in case you're interested, being treated as a relative domain explains what is happening. If your host is "example.com" the relative domain will eventually resolve to "gmail.con.com." which can be looked up, hence it wrongly claims "gmail.con" exists
This is a little code example that will validate an email address in two ways: - first the general syntax of the string is checked with a regular expression - then the domain substring (after the '@') is checked using the 'checkdnsrr' function
$this->_buf - for bulk check cache function ValidateEmail($email) { list($user, $domain) = explode('@', $email); if (!filter_var($email, FILTER_VALIDATE_EMAIL) !== FALSE) return 0; if (isset($this->_buf[$domain])) return $this->_buf[$domain]; if (checkdnsrr($domain) === FALSE) { $this->_buf[$domain] = 0; return 0; } $this->_buf[$domain] = 1; return 1; }
Is not possible validate domains with 'ñ' for my country. In my country is possible to register domain using 'ñ' character. For example: ñandu.cl http://nic.cl/cgi-bin/dom-CL?q=%F1andu If I use this function to check DNS record, it return false, but the domain already exists: var_dump(checkdnsrr('ñandu.cl', 'A')); // returns false
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
免责声明:我们致力于保护作者版权,注重分享,当前被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理!邮箱:344225443@qq.com)
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!
内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)