當前位置: 首頁>>代碼示例>>Python>>正文


Python dnslib.RR屬性代碼示例

本文整理匯總了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,
        ) 
開發者ID:samuelcolvin,項目名稱:dnserver,代碼行數:26,代碼來源:dnserver.py

示例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" 
開發者ID:faicker,項目名稱:greendns,代碼行數:20,代碼來源:test_handler_greendns.py

示例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" 
開發者ID:faicker,項目名稱:greendns,代碼行數:20,代碼來源:test_handler_greendns.py

示例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" 
開發者ID:faicker,項目名稱:greendns,代碼行數:20,代碼來源:test_handler_greendns.py

示例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 
開發者ID:faicker,項目名稱:greendns,代碼行數:18,代碼來源:test_handler_greendns.py

示例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 
開發者ID:alexsilva,項目名稱:MINI-DNS-Server,代碼行數:22,代碼來源:dns.py

示例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() 
開發者ID:Tr3jer,項目名稱:dnsAutoRebinding,代碼行數:29,代碼來源:main.py

示例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) 
開發者ID:expressvpn,項目名稱:expressvpn_leak_testing,代碼行數:4,代碼來源:dns_server.py

示例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) 
開發者ID:pan-unit42,項目名稱:public_tools,代碼行數:38,代碼來源:wekby_dns.py

示例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) 
開發者ID:faicker,項目名稱:greendns,代碼行數:13,代碼來源:test_server.py

示例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 
開發者ID:faicker,項目名稱:greendns,代碼行數:17,代碼來源:test_handler_greendns.py

示例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 
開發者ID:faicker,項目名稱:greendns,代碼行數:16,代碼來源:test_handler_greendns.py

示例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 
開發者ID:faicker,項目名稱:greendns,代碼行數:17,代碼來源:test_handler_greendns.py

示例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" 
開發者ID:faicker,項目名稱:greendns,代碼行數:29,代碼來源:test_handler_greendns.py

示例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()) 
開發者ID:LyleMi,項目名稱:Saker,代碼行數:17,代碼來源:dnsrebinding.py


注:本文中的dnslib.RR屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。