Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass stdin into Unix host or dig command

Tags:

host

dig

Let's say I have a list of IPs coming into a log that I'm tailing:

1.1.1.1
1.1.1.2
1.1.1.3 

I'd like to easily resolve them to host names. I'd like to be able to

tail -f access.log | host - 

Which fails as host doesn't understand input from stdin in this way. What's the easiest way to do with without having to write a static file or fallback to perl/python/etc.?

like image 249
tomasz Avatar asked Aug 07 '09 20:08

tomasz


People also ask

What is dig command in Unix?

The dig (domain information groper) command is a flexible tool for interrogating DNS name servers. It performs DNS lookups and displays the answers that are returned from the queried name server(s).

How does dig command work?

The DIG command works by performing a DNS query from your device to the targeted IP address or hostname. The query will first arrive at your ISP's recursive name servers. If there, it has your answer, it will return it fast. If no, your query will be re-routed in search of the answer.

What is the difference between nslookup and dig commands?

dig uses the OS resolver libraries. nslookup uses is own internal ones. That is why Internet Systems Consortium (ISC) has been trying to get people to stop using nslookup for some time now.

When using the dig command for DNS lookups What does the symbol used for?

By default, dig commands will query the name servers listed in /etc/resolv. conf to perform a DNS lookup for you. You can change this default behavior by using the @ symbol followed by a hostname or IP address of the name server along. The following dig command sends the DNS query to Google's name server(8.8.


2 Answers

Use xargs -l:

tail -f access.log | xargs -l host
like image 91
Sinan Taifour Avatar answered Sep 21 '22 06:09

Sinan Taifour


You could also use the read builtin:

tail -f access.log | while read line; do host $line; done
like image 25
Jukka Matilainen Avatar answered Sep 19 '22 06:09

Jukka Matilainen