txtrecord_decode.py
· 453 B · Python
Raw
#!/usr/bin/env python3
# txtrecord_decode.py output.png logo.example.com
import dns.resolver # pip3 install dnspython
import base64
import sys
q = dns.resolver.query(sys.argv[2],"TXT").response.answer[0]
out = b""
for line in sorted(_.strings[0] for _ in q):
if chr(line[0]) == "{":
try:
out += line.split(b"}",1)[1]
except IndexError:
pass
with open(sys.argv[1],"wb") as f:
f.write(base64.b64decode(out))
| 1 | #!/usr/bin/env python3 |
| 2 | # txtrecord_decode.py output.png logo.example.com |
| 3 | import dns.resolver # pip3 install dnspython |
| 4 | import base64 |
| 5 | import sys |
| 6 | q = dns.resolver.query(sys.argv[2],"TXT").response.answer[0] |
| 7 | out = b"" |
| 8 | for line in sorted(_.strings[0] for _ in q): |
| 9 | if chr(line[0]) == "{": |
| 10 | try: |
| 11 | out += line.split(b"}",1)[1] |
| 12 | except IndexError: |
| 13 | pass |
| 14 | with open(sys.argv[1],"wb") as f: |
| 15 | f.write(base64.b64decode(out)) |
txtrecord_encode.py
· 440 B · Python
Raw
#!/usr/bin/env python3
# txtrecord_encode.py input.png logo.example.com
import base64
import sys
from textwrap import wrap
with open(sys.argv[1],"rb") as f:
enc = base64.b64encode(f.read()).decode("utf-8")
# '%04d' and '247' may need to be updated for large files to ensure the line count doesn't push the length
# longer than 255 bytes
print("\n".join("%s. IN TXT '{%04d}%s'" % (sys.argv[2], n,s) for n,s in enumerate(wrap(enc,247))))
| 1 | #!/usr/bin/env python3 |
| 2 | # txtrecord_encode.py input.png logo.example.com |
| 3 | import base64 |
| 4 | import sys |
| 5 | from textwrap import wrap |
| 6 | with open(sys.argv[1],"rb") as f: |
| 7 | enc = base64.b64encode(f.read()).decode("utf-8") |
| 8 | |
| 9 | # '%04d' and '247' may need to be updated for large files to ensure the line count doesn't push the length |
| 10 | # longer than 255 bytes |
| 11 | print("\n".join("%s. IN TXT '{%04d}%s'" % (sys.argv[2], n,s) for n,s in enumerate(wrap(enc,247)))) |