emilstahl
emilstahl

Reputation: 23

Piping IP address from dig to whois

I want to get the IP address of a domain name with dig and then perform a whois lookup on that IP address.

I tried this:

dig domain.dk +short | whois

Upvotes: 1

Views: 4084

Answers (1)

Alex Riley
Alex Riley

Reputation: 177078

One option is just to write:

whois $(dig example.com +short)

Note that multiple IP addresses might be returned by dig so whois might sometimes complain that it doesn't know which whois server to use. In that case you might want to choose which of the IP addresses you look up. You could pick the first one with:

whois $(dig example.com +short | head -n1)

A more readable way that's also slightly closer to your original question is the following (pointed out by @tripleee in the comments):

dig +short example.com | xargs whois

(and dig +short example.com | head -n1 | xargs whois to look up just the first IP address returned by dig)

Upvotes: 2

Related Questions