I'm trying to incorporate DNS queries into a Python script for a project involving network security analysis. I’ve been using the dig command from the terminal to retrieve DNS records, but I’d like to automate this process through Python.
How can I use the subprocess module to run dig commands within my Python script and then parse the output for further analysis? If there’s a more Pythonic way to perform DNS queries (without shelling out to dig), I’d love to see an example of that as well!