Last active
March 16, 2018 16:42
-
-
Save Habbie/e6b3aec4077144825c2fcd51621459bb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
$ dig -t txt foo2.example.net @127.0.0.1 | |
; <<>> DiG 9.11.2 <<>> -t txt foo2.example.net @127.0.0.1 | |
;; global options: +cmd | |
;; Got answer: | |
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62695 | |
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 | |
;; WARNING: recursion requested but not available | |
;; OPT PSEUDOSECTION: | |
; EDNS: version: 0, flags:; udp: 1680 | |
;; QUESTION SECTION: | |
;foo2.example.net. IN TXT | |
;; ANSWER SECTION: | |
foo2.example.net. 3600 IN TXT "{\"glossary\":{\"title\":\"example glossary\",\"GlossDiv\":{\"title\":\"S\",\"GlossList\":{\"GlossEntry\":{\"ID\":\"SGML\",\"SortAs\":\"SGML\",\"GlossTerm\":\"Standard Generalized Markup Language\",\"Acronym\":\"SGML\",\"Abbrev\":\"ISO 8879:1986\",\"GlossDef\":{\"para\":\"A meta-markup language," " used to create markup languages such as DocBook.\",\"GlossSeeAlso\":[\"GML\",\"XML\"]},\"GlossSee\":\"markup\"}}}}}" | |
;; Query time: 5 msec | |
;; SERVER: 127.0.0.1#53(127.0.0.1) | |
;; WHEN: Fri Mar 16 15:16:15 CET 2018 | |
;; MSG SIZE rcvd: 419 | |
>>> import dns.name, dns.message, dns.query | |
>>> qname = dns.name.from_text('foo2.example.net'); q = dns.message.make_query(qname, dns.rdatatype.TXT); r = dns.query.udp(q, '127.0.0.1') | |
>>> txt=r.find_rrset(r.answer, qname, dns.rdataclass.IN, dns.rdatatype.TXT) | |
>>> txt[0].strings | |
[b'{"glossary":{"title":"example glossary","GlossDiv":{"title":"S","GlossList":{"GlossEntry":{"ID":"SGML","SortAs":"SGML","GlossTerm":"Standard Generalized Markup Language","Acronym":"SGML","Abbrev":"ISO 8879:1986","GlossDef":{"para":"A meta-markup language,', b' used to create markup languages such as DocBook.","GlossSeeAlso":["GML","XML"]},"GlossSee":"markup"}}}}}'] | |
>>> b''.join(txt[0].strings) | |
b'{"glossary":{"title":"example glossary","GlossDiv":{"title":"S","GlossList":{"GlossEntry":{"ID":"SGML","SortAs":"SGML","GlossTerm":"Standard Generalized Markup Language","Acronym":"SGML","Abbrev":"ISO 8879:1986","GlossDef":{"para":"A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso":["GML","XML"]},"GlossSee":"markup"}}}}}' | |
>>> import json | |
>>> json.loads(b''.join(txt[0].strings)) | |
{'glossary': {'title': 'example glossary', 'GlossDiv': {'title': 'S', 'GlossList': {'GlossEntry': {'ID': 'SGML', 'SortAs': 'SGML', 'GlossTerm': 'Standard Generalized Markup Language', 'Acronym': 'SGML', 'Abbrev': 'ISO 8879:1986', 'GlossDef': {'para': 'A meta-markup language, used to create markup languages such as DocBook.', 'GlossSeeAlso': ['GML', 'XML']}, 'GlossSee': 'markup'}}}}} | |
>>> |
This file contains hidden or 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
$ dig +short -t txt foo.example.net @127.0.0.1 | |
"{\"hi\":5}" |
This file contains hidden or 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 | |
import sys | |
import dns.name, dns.message, dns.query | |
qname = dns.name.from_text(sys.argv[1]); q = dns.message.make_query(qname, dns.rdatatype.TXT); r = dns.query.udp(q, sys.argv[2]) | |
txts=r.find_rrset(r.answer, qname, dns.rdataclass.IN, dns.rdatatype.TXT) | |
for txt in txts: | |
print(b''.join(txt.strings).decode('ascii')) |
This file contains hidden or 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
>>> import dns.name, dns.message, dns.query | |
>>> qname = dns.name.from_text('foo.example.net'); q = dns.message.make_query(qname, dns.rdatatype.TXT); r = dns.query.udp(q, '127.0.0.1') | |
>>> txt=r.find_rrset(r.answer, qname, dns.rdataclass.IN, dns.rdatatype.TXT) | |
>>> txt[0].strings | |
[b'{"hi":5}'] |
This file contains hidden or 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
$ ./txt.py foo2.example.net 127.0.0.1 | jq . | |
{ | |
"glossary": { | |
"title": "example glossary", | |
"GlossDiv": { | |
"title": "S", | |
"GlossList": { | |
"GlossEntry": { | |
"ID": "SGML", | |
"SortAs": "SGML", | |
"GlossTerm": "Standard Generalized Markup Language", | |
"Acronym": "SGML", | |
"Abbrev": "ISO 8879:1986", | |
"GlossDef": { | |
"para": "A meta-markup language, used to create markup languages such as DocBook.", | |
"GlossSeeAlso": [ | |
"GML", | |
"XML" | |
] | |
}, | |
"GlossSee": "markup" | |
} | |
} | |
} | |
} | |
} |
JakeDEvans
commented
Mar 16, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment