1

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?

1 Answer 1

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'}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.