Rodrigo Barron
Rodrigo Barron

Reputation: 23

Unix script to resolve hostnames from IP addresses

I've got a text file with a bunch of IPv4 addresses, and I'd like to know the hostname of each one in order to know if they are tor addresses. Is there a simple script that can help me to do that ?

Upvotes: 1

Views: 4563

Answers (1)

FatalError
FatalError

Reputation: 54631

You can loop using dig:

#!/bin/bash

while read line
do
    dig -x "$line" +short
done

Then given IPs 1 per line, you can run something like ./reverse.sh < addrs.txt.

Caveats: DNS is not a 1-to-1 mapping, and reverse DNS is somewhat less reliable than forward DNS.

Upvotes: 1

Related Questions