Matteo
Matteo

Reputation: 8142

How to resolve an IP-address on a private LAN and get the associated hostname in bash?

I am writing a bash script that collects information on the LAN to which I am connected.

After following instructions from post How can I write a linux bash script that tells me which computers are ON in my LAN?, I would like to collect some other information on the computers connected on my same LAN, such as their hostname.

I looked in the PING command man page but didn't find anything useful, and also checked NSLOOKUP command, but without success.

Are there any already existing bash commands which resolves IP addresses to hostnames on a private LAN?

In case not, do you have some ideas on how to write a script for getting it?

Upvotes: 0

Views: 1701

Answers (2)

Eugene Yarmash
Eugene Yarmash

Reputation: 150041

You can use dig:

dig +short -x 64.34.119.12 
stackoverflow.com.

Upvotes: 0

Rahul
Rahul

Reputation: 77906

Have you tried host command like

host 204.152.191.5

Upvotes: 2

Related Questions