<p>There may be other ways to achieve this.  But the most elegant way we found was using python's socket library.</p>
<p>You can get all the info in a one liner, and extract it into a list in another line.  It's fast, short, readable, and easy to put in a loop against a ton of records.</p>
<p><strong>The Code</strong></p>
<pre><code>import socket

net_info = socket.getaddrinfo(&quot;stackoverflow.com&quot;, None)
ip_list = set([x[0] for x in [x[4] for x in net_info]])

print(ip_list)
</code></pre>
<p><strong>Output</strong></p>
<pre><code>{'151.101.129.69', '151.101.1.69', '151.101.193.69', '151.101.65.69'}

</code></pre>

CC BY-SA 4.0
2022-01-13T23:16:47.650Z
2022-01-13T23:16:47.650Z
John Humphreys
<p>We're trying to look at a fairly large httpd config and find the all the IPs/ports we'd have to allow through a new firewall.</p>
<p>Ports are easy, but resolving all the DNS names to the (multiple) IPs they may have and outputting it in easy-to-consume manner seems hard.</p>
<p>What's the best way?</p>

<dns><ip><network>
How can you map DNS/host names to their IPs at scale?
John Humphreys
# How can you map DNS/host names to their IPs at scale?

(Asked by: username_0 on 2022-01-13)

We're trying to look at a fairly large httpd config and find the all the IPs/ports we'd have to allow through a new firewall.

Ports are easy, but resolving all the DNS names to the (multiple) IPs they may have and outputting it in easy-to-consume manner seems hard.

What's the best way?

**Tags:** dns, ip, network


---

## 1 answers

### Answer by username_0 on 2022-01-13. Score: 2

There may be other ways to achieve this.  But the most elegant way we found was using python's socket library.
You can get all the info in a one liner, and extract it into a list in another line.  It's fast, short, readable, and easy to put in a loop against a ton of records.
The Code
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'}


---

