I have a list of IP addresses and MAC addresses connected to my local network, but I need to get the hostnames of each device, is there a command line or terminal (mac) command for this?
host IP should do it:
jed@jed-osx:~$ host 22.214.171.124 126.96.36.199.in-addr.arpa domain name pointer vnsc-bak.sys.gtei.net.
As Zoredache mentions in the comments, this is not going to work if DNS isn't set up properly. Of course, if that is the case, then you have very limited options. The only method that I can think of is to connect to the IP and ask it what its hostname is (e.g. if you can ssh to it, you can then perform the
hostname command to see what it thinks its name is:
ssh user@the-ip-address hostname).
1That presumes that the reverse DNS is setup and updated. If DNS is not setup or maintained then host won't do anything useful. Dec 6, 2010 at 21:59
4@Zoredache, presumably if DNS is not set up properly, then there won't be any way to get a host's name from its IP.– nhinkleDec 6, 2010 at 22:29
Another great answer is:
$ dig -x 188.8.131.52 ; <<>> DiG 9.10.6 <<>> -x 184.108.40.206 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 28070 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 1232 ;; QUESTION SECTION: ;220.127.116.11.in-addr.arpa. IN PTR ;; ANSWER SECTION: 18.104.22.168.in-addr.arpa. 146 IN PTR one.one.one.one. ;; Query time: 30 msec ;; SERVER: 22.214.171.124#53(126.96.36.199) ;; WHEN: Fri Apr 23 02:35:37 CDT 2021 ;; MSG SIZE rcvd: 78