We were recently trying to find all the IPs we needed to open in a firewall from an Apache proxy. So, we had to resolve a huge number of DNS records to IPs (and relevant ports) programmatically.
I found this very elegant way of getting all the IPs for a DNS name, I hope you find it useful!
import socket
net_info = socket.getaddrinfo("stackoverflow.com", None)
ip_list = set([x[0] for x in [x[4] for x in net_info]])
print(ip_list)
Output:
{'151.101.129.69', '151.101.1.69', '151.101.193.69', '151.101.65.69'}