Skip to content

Modifying the answer from dns.query.udp #1070

Answered by rthalley
GamePlayer-8 asked this question in Q&A
Discussion options

You must be logged in to vote

This response is slightly more general than your question, in that it shows you how to change a field of an rdata and replace it in the response. In your case, replacing an rdata field and replacing the whole rdata are the same as A records only have one field, but this technique would work if you (say) wanted to change the priority of an MX record without changing its target.

for answer in response.answer:
    if answer.rdtype == dns.rdatatype.A:
        new_rdatas = dns.rdataset.Rdataset(answer.rdclass, answer.rdtype)
        for rdata in answer:
            if rdata.address == "127.0.0.1":
                new_rdata = rdata.replace(address="127.0.0.2")
                new_rdatas.add(new…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@GamePlayer-8
Comment options

Answer selected by GamePlayer-8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants