本文整理汇总了Python中twisted.names.dns.NS属性的典型用法代码示例。如果您正苦于以下问题:Python dns.NS属性的具体用法?Python dns.NS怎么用?Python dns.NS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类twisted.names.dns
的用法示例。
在下文中一共展示了dns.NS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _referralTest
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import NS [as 别名]
def _referralTest(self, method):
"""
Create an authority and make a request against it. Then verify that the
result is a referral, including no records in the answers or additional
sections, but with an I{NS} record in the authority section.
"""
subdomain = 'example.' + str(soa_record.mname)
nameserver = dns.Record_NS('1.2.3.4')
authority = NoFileAuthority(
soa=(str(soa_record.mname), soa_record),
records={
subdomain: [
nameserver,
]})
d = getattr(authority, method)(subdomain)
result = []
d.addCallback(result.append)
answer, authority, additional = result[0]
self.assertEquals(answer, [])
self.assertEquals(
authority, [dns.RRHeader(
subdomain, dns.NS, ttl=soa_record.expire,
payload=nameserver, auth=False)])
self.assertEquals(additional, [])
示例2: extractAuthority
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import NS [as 别名]
def extractAuthority(msg, cache):
records = msg.answers + msg.authority + msg.additional
nameservers = [r for r in records if r.type == dns.NS]
# print 'Records for', soFar, ':', records
# print 'NS for', soFar, ':', nameservers
if not nameservers:
return None, nameservers
if not records:
raise IOError("No records")
for r in records:
if r.type == dns.A:
cache[str(r.name)] = r.payload.dottedQuad()
for r in records:
if r.type == dns.NS:
if str(r.payload.name) in cache:
return cache[str(r.payload.name)], nameservers
for addr in records:
if addr.type == dns.A and addr.name == r.name:
return addr.payload.dottedQuad(), nameservers
return None, nameservers
示例3: lookupNameservers
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import NS [as 别名]
def lookupNameservers(self, name, timeout=None):
return self._lookup(name, dns.IN, dns.NS, timeout)
示例4: extractRecord
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import NS [as 别名]
def extractRecord(resolver, name, answers, level=10):
if not level:
return None
if hasattr(socket, 'inet_ntop'):
for r in answers:
if r.name == name and r.type == dns.A6:
return socket.inet_ntop(socket.AF_INET6, r.payload.address)
for r in answers:
if r.name == name and r.type == dns.AAAA:
return socket.inet_ntop(socket.AF_INET6, r.payload.address)
for r in answers:
if r.name == name and r.type == dns.A:
return socket.inet_ntop(socket.AF_INET, r.payload.address)
for r in answers:
if r.name == name and r.type == dns.CNAME:
result = extractRecord(
resolver, r.payload.name, answers, level - 1)
if not result:
return resolver.getHostByName(
str(r.payload.name), effort=level - 1)
return result
# No answers, but maybe there's a hint at who we should be asking about
# this
for r in answers:
if r.type == dns.NS:
from twisted.names import client
r = client.Resolver(servers=[(str(r.payload.name), dns.PORT)])
return r.lookupAddress(str(name)
).addCallback(
lambda records: extractRecord(
r, name,
records[_ANS] + records[_AUTH] + records[_ADD],
level - 1))
示例5: test_nameserver
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import NS [as 别名]
def test_nameserver(self):
"""Test DNS 'NS' record queries"""
return self.namesTest(
self.resolver.lookupNameservers('test-domain.com'),
[dns.Record_NS('39.28.189.39', ttl=19283784)]
)
示例6: setUp
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import NS [as 别名]
def setUp(self):
self.results = None
self.d = defer.Deferred()
self.d.addCallback(self._gotResults)
self.controller = client.AXFRController('fooby.com', self.d)
self.soa = dns.RRHeader(name='fooby.com', type=dns.SOA, cls=dns.IN, ttl=86400, auth=False,
payload=dns.Record_SOA(mname='fooby.com',
rname='hooj.fooby.com',
serial=100,
refresh=200,
retry=300,
expire=400,
minimum=500,
ttl=600))
self.records = [
self.soa,
dns.RRHeader(name='fooby.com', type=dns.NS, cls=dns.IN, ttl=700, auth=False,
payload=dns.Record_NS(name='ns.twistedmatrix.com', ttl=700)),
dns.RRHeader(name='fooby.com', type=dns.MX, cls=dns.IN, ttl=700, auth=False,
payload=dns.Record_MX(preference=10, exchange='mail.mv3d.com', ttl=700)),
dns.RRHeader(name='fooby.com', type=dns.A, cls=dns.IN, ttl=700, auth=False,
payload=dns.Record_A(address='64.123.27.105', ttl=700)),
self.soa
]
示例7: test_recordMissing
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import NS [as 别名]
def test_recordMissing(self):
"""
If a L{FileAuthority} has a zone which includes an I{NS} record for a
particular name and that authority is asked for another record for the
same name which does not exist, the I{NS} record is not included in the
authority section of the response.
"""
authority = NoFileAuthority(
soa=(str(soa_record.mname), soa_record),
records={
str(soa_record.mname): [
soa_record,
dns.Record_NS('1.2.3.4'),
]})
d = authority.lookupAddress(str(soa_record.mname))
result = []
d.addCallback(result.append)
answer, authority, additional = result[0]
self.assertEqual(answer, [])
self.assertEqual(
authority, [
dns.RRHeader(
str(soa_record.mname), soa_record.TYPE,
ttl=soa_record.expire, payload=soa_record,
auth=True)])
self.assertEqual(additional, [])
示例8: test_referral
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import NS [as 别名]
def test_referral(self):
"""
When an I{NS} record is found for a child zone, it is included in the
authority section of the response. It is marked as non-authoritative if
the authority is not also authoritative for the child zone (RFC 2181,
section 6.1).
"""
self._referralTest('lookupAddress')
示例9: _additionalNSTest
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import NS [as 别名]
def _additionalNSTest(self, addresses):
"""
Verify that a response to an NS query has certain records in the
I{additional} section.
@param addresses: See C{_additionalTest}
"""
self._additionalTest(
"lookupNameservers", dns.Record_NS, addresses)
示例10: test_nameserverAdditionalA
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import NS [as 别名]
def test_nameserverAdditionalA(self):
"""
If the name of the NS response has A records, they are included in the
additional section of the response.
"""
self._additionalNSTest([self._A])
示例11: test_nameserverAdditionalAAAA
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import NS [as 别名]
def test_nameserverAdditionalAAAA(self):
"""
If the name of the NS response has AAAA records, they are included in
the additional section of the response.
"""
self._additionalNSTest([self._AAAA])
示例12: test_nameserverAdditionalBoth
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import NS [as 别名]
def test_nameserverAdditionalBoth(self):
"""
If the name of the NS response has both A and AAAA records, they are
all included in the additional section of the response.
"""
self._additionalNSTest([self._A, self._AAAA])
示例13: test_ns
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import NS [as 别名]
def test_ns(self):
"""
The repr of a L{dns.Record_NS} instance includes the name of the
nameserver and the TTL of the record.
"""
self.assertEqual(
repr(dns.Record_NS(b'example.com', 4321)),
"<NS name=example.com ttl=4321>")
示例14: lookupNameservers
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import NS [as 别名]
def lookupNameservers(host, atServer, p=None):
warnings.warn(
'twisted.names.root.lookupNameservers is deprecated since Twisted '
'10.0. Use twisted.names.root.Resolver.lookupNameservers instead.',
category=DeprecationWarning, stacklevel=2)
# print 'Nameserver lookup for', host, 'at', atServer, 'with', p
if p is None:
p = dns.DNSDatagramProtocol(_DummyController())
p.noisy = False
return retry(
(1, 3, 11, 45), # Timeouts
p, # Protocol instance
(atServer, dns.PORT), # Server to query
[dns.Query(host, dns.NS, dns.IN)] # Question to ask
)
示例15: extractAuthority
# 需要导入模块: from twisted.names import dns [as 别名]
# 或者: from twisted.names.dns import NS [as 别名]
def extractAuthority(msg, cache):
warnings.warn(
'twisted.names.root.extractAuthority is deprecated since Twisted '
'10.0. Please inspect the Message object directly.',
category=DeprecationWarning, stacklevel=2)
records = msg.answers + msg.authority + msg.additional
nameservers = [r for r in records if r.type == dns.NS]
# print 'Records for', soFar, ':', records
# print 'NS for', soFar, ':', nameservers
if not nameservers:
return None, nameservers
if not records:
raise IOError("No records")
for r in records:
if r.type == dns.A:
cache[str(r.name)] = r.payload.dottedQuad()
for r in records:
if r.type == dns.NS:
if str(r.payload.name) in cache:
return cache[str(r.payload.name)], nameservers
for addr in records:
if addr.type == dns.A and addr.name == r.name:
return addr.payload.dottedQuad(), nameservers
return None, nameservers