-
Notifications
You must be signed in to change notification settings - Fork 44
/
hostnametoips.py
executable file
·31 lines (26 loc) · 972 Bytes
/
hostnametoips.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python3
import dns.resolver
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Resolve domains and get list of IPs')
parser.add_argument('FILE', help='File containing list of domains')
parser.add_argument('--verbose', '-v', action='store_true',
help='File containing list of domains')
args = parser.parse_args()
with open(args.FILE) as f:
data = f.read().split('\n')
res = dns.resolver.Resolver()
ips = set()
for d in data:
if d.strip != '':
try:
ans = res.query(d.strip(), "A")
for ip in ans:
if args.verbose:
print("%s - %s" % (d.strip(), ip.to_text()))
ips.add(ip.to_text())
except dns.resolver.NXDOMAIN:
if args.verbose:
print("%s - no domain" % d.strip())
for ip in ips:
print(ip)