dnspython如何查找子域名的序列号?

发布于 2024-12-23 17:57:10 字数 2276 浏览 1 评论 0原文

我有一个小问题,我似乎无法解决问题。我正在尝试查询子域的序列号。虽然我一直没有得到答案错误,但它在根域上可以正常工作。如果我只是告诉你:

import socket, dns.resolver
host = "google.com"
querytype = "SOA"
cachingserverslist = {'server1': '4.1.1.1', 'server2': '4.2.2.2'}

for cachingservername, cachingserver in sorted(cachingserverslist.iteritems()) :
    query = dns.resolver.Resolver()
    query.nameservers=[socket.gethostbyname(cachingserver)]
    query.Timeout = 2.0

for a in query.query( host , querytype ) :
      print a.serial

这会给我预期的结果,那就更容易了。我不明白的是,当我将主机变量更改为任何子域或 www 时,它会出错且没有答案。这是一个 ipython 会话,它显示了我的意思:

In [1]: import socket, dns.resolver
In [2]: host = "google.com"
In [3]: querytype = "SOA"
In [4]: cachingserverslist = {'server1': '4.1.1.1', 'server2': '4.2.2.2'}
In [5]: for cachingservername, cachingserver in sorted(cachingserverslist.iteritems())     :
...:             query = dns.resolver.Resolver()
...:         query.nameservers=[socket.gethostbyname(cachingserver)]
...:         query.Timeout = 2.0
...: 

In [6]: for a in query.query( host , querytype ) :
   ...:               print a.serial
   ...: 
2011121901

In [7]:
In [8]: host = "www.google.com"
In [9]: for a in query.query( host , querytype ) :
      print a.serial
   ....:     
   ....:     
---------------------------------------------------------------------------
NoAnswer                                  Traceback (most recent call last)

/var/www/pydns/<ipython console> in <module>()

/usr/local/lib/python2.6/dist-packages/dns/resolver.pyc in query(self, qname, rdtype,     rdclass, tcp, source, raise_on_no_answer)
707             raise NXDOMAIN
708         answer = Answer(qname, rdtype, rdclass, response,
--> 709                         raise_on_no_answer)
710         if self.cache:
711             self.cache.put((qname, rdtype, rdclass), answer)

/usr/local/lib/python2.6/dist-packages/dns/resolver.pyc in __init__(self, qname, rdtype, rdclass, response, raise_on_no_answer)
    127                     except KeyError:
    128                         if raise_on_no_answer:
--> 129                             raise NoAnswer
    130                 if raise_on_no_answer:
    131                     raise NoAnswer

    NoAnswer: 

任何见解将不胜感激。谢谢。

I have a little issue I cannot seem to get my head get around. I am trying to query the serial number of a sub-domain. I keep getting no answer error tho but it will work fine on root domains. Easier if I just show you:

import socket, dns.resolver
host = "google.com"
querytype = "SOA"
cachingserverslist = {'server1': '4.1.1.1', 'server2': '4.2.2.2'}

for cachingservername, cachingserver in sorted(cachingserverslist.iteritems()) :
    query = dns.resolver.Resolver()
    query.nameservers=[socket.gethostbyname(cachingserver)]
    query.Timeout = 2.0

for a in query.query( host , querytype ) :
      print a.serial

Which gives me the expected result. What I don't understand is when I change the host variable to any subdomain or www's it errors out with a no answer. Here is an ipython session which shows what I mean:

In [1]: import socket, dns.resolver
In [2]: host = "google.com"
In [3]: querytype = "SOA"
In [4]: cachingserverslist = {'server1': '4.1.1.1', 'server2': '4.2.2.2'}
In [5]: for cachingservername, cachingserver in sorted(cachingserverslist.iteritems())     :
...:             query = dns.resolver.Resolver()
...:         query.nameservers=[socket.gethostbyname(cachingserver)]
...:         query.Timeout = 2.0
...: 

In [6]: for a in query.query( host , querytype ) :
   ...:               print a.serial
   ...: 
2011121901

In [7]:
In [8]: host = "www.google.com"
In [9]: for a in query.query( host , querytype ) :
      print a.serial
   ....:     
   ....:     
---------------------------------------------------------------------------
NoAnswer                                  Traceback (most recent call last)

/var/www/pydns/<ipython console> in <module>()

/usr/local/lib/python2.6/dist-packages/dns/resolver.pyc in query(self, qname, rdtype,     rdclass, tcp, source, raise_on_no_answer)
707             raise NXDOMAIN
708         answer = Answer(qname, rdtype, rdclass, response,
--> 709                         raise_on_no_answer)
710         if self.cache:
711             self.cache.put((qname, rdtype, rdclass), answer)

/usr/local/lib/python2.6/dist-packages/dns/resolver.pyc in __init__(self, qname, rdtype, rdclass, response, raise_on_no_answer)
    127                     except KeyError:
    128                         if raise_on_no_answer:
--> 129                             raise NoAnswer
    130                 if raise_on_no_answer:
    131                     raise NoAnswer

    NoAnswer: 

Any insight would be most appreciated. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情何以堪。 2024-12-30 17:57:10

序列号是 SOA“授权起始”记录的一个属性。 www.google.com 是 CNAME,因此没有与之关联的序列号。

The serial number is an attribute of the SOA 'start of authority' record. www.google.com is a CNAME, so it doesn't have a serial number associated with it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文