-1

I made some research and can't find a solution, I'm starting to think this is not possible.

I'm running arp -a in my terminal and I'd like to get the hostnames of the LAN devices.

host x.x.x.x returns:

Host x.x.x.x.in-addr.arpa. not found: 3(NXDOMAIN)

nslookup x.x.x.x returns:

** server can't find x.x.x.x.in-addr.arpa: NXDOMAIN

Is there a way to do this?

Marie Dm
  • 2,637
  • 3
  • 24
  • 43
  • 1
    Is there a DNS server on the LAN that can serve reverse lookup requests? If so, just add that to the `host` command (`host x.x.x.x serverip`), and maybe use that in your system settings so everything (like `arp`) can see the names. If not, then by definition there's no way to do it. There may be other ways to look up names on the LAN, but without a server reverse DNS won't work. – Gordon Davisson Sep 08 '18 at 11:34
  • Thanks you put me on the right track, I found a solution. – Marie Dm Sep 08 '18 at 17:18

2 Answers2

0

arp -a does the reverse DNS by default on linux machines. On macOS I guess you will have to run nslookup on each entry returned by arp -a table.

mdeora
  • 4,152
  • 2
  • 19
  • 29
0

I found a way thanks to @gordon-davisson who set me on the right path.

First I get the gateway IP with: route get default | grep gateway

Then for every LAN device I run: host LAN_IP Gateway_IP

This returns:

Using domain server:
Name: 192.168.x.x
Address: 192.168.x.x#x
Aliases: 

x.x.168.192.in-addr.arpa domain name pointer LAN-host-name.

I parse the response to get the name displayed at the end.

Side note: it still doesn't display the LAN host-names with arp -a after that.

Marie Dm
  • 2,637
  • 3
  • 24
  • 43
  • 1
    Ok, now I'm curious why that DNS server isn't being used by the system resolver. It sounds like you have the standard all-in-one router-DHCPserver-DNSserver, in which case why isn't it handing itself out as the DNS server to use? You can check what server you're actually using in Network preferences (Advanced -> DNS tab) or with `more /etc/resolv.conf`, and see what the DHCP service is handing out with `ipconfig getpacket en0` (or `en1` or whatever) and looking at the "domain_name_server" line. – Gordon Davisson Sep 08 '18 at 18:12
  • @GordonDavisson I'm using Google DNS (8.8.8.8 and 8.8.4.4). As for the DHCP, domain_name_server is the IP of the router. – Marie Dm Sep 18 '18 at 17:37
  • I'd recommend changing that -- have your Mac use the local router as its server, and then configure the router to query Google DNS. That way local lookups work system-wide, and everything nonlocal gets forwarded to Google anyway. – Gordon Davisson Sep 18 '18 at 18:08
  • It depends on your network settings. You can view and change them with the `networksetup` command, but it's really much easier to use the Network pane in System Preferences. Actually, I guess the first question is whether you're using the DNS server addresses provided by the router's DHCP service (in which case you should figure out how to fix it at the router) or overriding that in the Mac's network settings (in which case you should stop overriding it there). – Gordon Davisson Sep 21 '18 at 07:09