Created
July 20, 2015 16:22
-
-
Save misaka4e21/e8e7a8927c2293fc593b to your computer and use it in GitHub Desktop.
A DNS server returns only IPv6 address when AAAA record is available.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Copyright (C) R.O.C.2015 Misaka Network <[email protected]> | |
# License under WTFPL | |
from dnslib.server import * | |
from dnslib import * | |
class TestResolv: | |
def resolve(self,request,handler): | |
ipv4=False | |
if request.q.qtype == QTYPE.A: | |
ipv4=True | |
request.q.qtype=QTYPE.AAAA | |
fw=DNSRecord(q=request.q) | |
b=fw.send("2001:470:20::2",port=53,tcp=True,ipv6=True) | |
reply=request.reply() | |
answer = DNSRecord.parse(b) | |
result_a = [] | |
result_aaaa = [] | |
for i in answer.rr: | |
if i.rtype == QTYPE.AAAA: | |
result_aaaa.append(i) | |
elif i.rtype == QTYPE.A: | |
result_a.append(i) | |
else: | |
reply.add_answer(i) | |
if ipv4: | |
if result_aaaa == []: | |
request.q.qtype=QTYPE.A | |
b=DNSRecord(q=request.q).send("2001:470:20::2",tcp=True,ipv6=True) | |
for i in DNSRecord.parse(b).rr: | |
reply.add_answer(i) | |
return reply | |
else: | |
for i in result_aaaa: | |
reply.add_answer(i) | |
for i in reply.questions: | |
i.qtype=QTYPE.A | |
reply.set_header_qa() | |
return reply | |
resolver = TestResolv() | |
logger = DNSLogger(prefix=False) | |
server = DNSServer(resolver,port=53,address="0.0.0.0") | |
server.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment