使用NetDNS或get_dns_record获取Cname记录 [英] Get Cname records with NetDNS or get_dns_record

查看:87
本文介绍了使用NetDNS或get_dns_record获取Cname记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PHP获取CNAME记录的列表.

I'm trying get a list of CNAME records using PHP.

当我将代码托管在旧的Windows 7计算机上时,此方法曾经有效,但是我将其移至Ubuntu计算机(类似AMP堆栈设置),并且不再为 $ url返回CNAME记录..我将代码上传到Windows服务器,但仍然没有CNAME记录.

This method used to work when I was hosting the code on my old Windows 7 machine, but I moved it to an Ubuntu machine (similar AMP stack setup), and it no longer returned CNAME records for the $url. I uploaded the code to a Windows server and still yet, no CNAME records.

$records['cname'] = dns_get_record($url, DNS_CNAME);

并不是说我在说操作系统与任何事情都有很大关系,也许我在旧计算机上设置了某种方式可以使其正常工作.当前,它返回一个简单的空数组,该数组用于返回与我的DNS管理服务中的内容匹配的CNAME记录的列表.我在这里阅读了这篇文章:

Not that I'm claiming the OS has much to do with anything, maybe I had something set up a certain way on my old machine that allowed this to work. It currently returns a simple empty array, where as it used to return a list of CNAME records that matched up with what was in my DNS management service. I've read the article here:

为什么dns_get_record不当我知道它们存在时显示CNAME吗?

,最终尝试使用以下代码使用Pear的NetDns2库实现该功能.而且,响应的 answer 数组为空.不确定从get_dns_record到NetDNS2的问题是否相同,或者在这两种情况下我都做错了什么,但是经过测试的网站肯定具有CNAME记录,包括 google.com yahoo.com .

and ended up trying to implement the functionality with Pear's NetDns2 Library, with the following code. And still, the answer array of the response is empty. Not sure if the problem is the same from get_dns_record to NetDNS2 or if I'm doing something wrong in both cases, but the sites tested surely have CNAME records, including google.com and yahoo.com.

//using Google Name Server
$rslvr = new Net_DNS2_Resolver(array('nameservers' => array('8.8.8.8')));
$records['cname'] = $rslvr->query($url, 'CNAME');

感谢任何帮助,最终目标是能够像在旧计算机上一样获得CNAME记录的列表.

Any help is appreciated, the end goal is to be able to obtain a list of CNAME records like I was on my old machine.

推荐答案

在此可与PHP 5.4.9一起使用.

Works here with PHP 5.4.9.

第一个记录(cweiske.de)不是 CNAME ,而是直接指向IP地址:

The first record (cweiske.de) is no CNAME but directly points to an IP address:

php > var_dump(dns_get_record('cweiske.de', DNS_CNAME));
array(0) {
}

第二个实际上是第一个记录的CNAME:

The second is actually a CNAME to the first record:

php > var_dump(dns_get_record('www.cweiske.de', DNS_CNAME));
array(1) {
  [0] =>
  array(5) {
    'host' =>
    string(14) "www.cweiske.de"
    'class' =>
    string(2) "IN"
    'ttl' =>
    int(86400)
    'type' =>
    string(5) "CNAME"
    'target' =>
    string(10) "cweiske.de"
  }
}

dig 显示相同的内容:

$ dig cweiske.de
cweiske.de.     577 IN  A   83.169.7.198

$ dig www.cweiske.de
www.cweiske.de.     86397   IN  CNAME   cweiske.de.
cweiske.de.     597 IN  A   83.169.7.198

要检查是您的问题还是PHP的问题,请使用dig或nslookup进行测试.

To check if it's your or PHP's problem, use dig or nslookup to test.

这篇关于使用NetDNS或get_dns_record获取Cname记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆