I am working on a project where I have to build a REST API on cybersecurity related topics and for that I choose web app enumeration and now i am working on this code but i need the outupt to be in JSON to return the data to the client side how can I implement it?
import dns.resolver import sys
record_types = ['A', 'AAAA', 'NS', 'CNAME', 'MX', 'PTR', 'SOA', 'TXT'] try: domain = sys.argv[1] except IndexError: print('Syntax error - python3 dnsenum.py domainname')
for records in record_types: try: answer = dns.resolver.resolve(domain, records) print(f'\n{records} Records') print('-' * 30) for server in answer: print(server.to_text()) except dns.resolver.NoAnswer: pass except dns.resolver.NXDOMAIN: print(f'{domain} does not exist.') quit() except KeyboardInterrupt: print('Quitting.') quit()
I tried to add this data to a text file by appending it and then try converting it and it did not work as it is not a dictionery data to convert into I just want a lead into how I can convert this code into a returnable JSON data