Get computer name from IP-address

From the Terminal.app (or equivalent) you can use the host command to show the network name of the computer. This returns the name even if it has all sharing settings turned off and thus not showing via Finder.

For example, in my network I get the following (where I know the IP-address and the first part of the returned name is the computer's name)

➜ ~ host 192.168.2.135

135.2.168.192.in-addr.arpa domain name pointer raspberrypi.private.lan.

It depends on the actual name of the computer if the network name is exactly the same, as in your example, I guess it would become Jacobs-MacBook.


Without further access to the host (e.g. ssh or ARD) and no service running on it (e.g. iTunes Music Sharing/File Sharing) you can't get the computer name based on the IP-address.

The computer name in macOS is not necessarily indentical to the hostname or the Bonjour name! You can simply check this with scutil --get { ComputerName | LocalHostName | HostName }. ComputerName is the user friendly name, LocalHostname is the Bonjour name - both also visible in System Preferences > Sharing - and HostName is the hostname of the device. The hostname is usually related to or used with DNS, NIS, hosts file or similar methods of name resolution. On a newly installed consumer system no hostname is set. ComputerName and LocalHostName are usually derived from the first user's name and the Mac model (e.g. Admin's iMac | Admins-iMac).

Without a name record for the remote Mac in your hosts file or on a DNS-server in your local or a public network neither of the tools mentioned in the other answers (arp, ping, host) can be used to resolve the hostname.

If a known Bonjour service is running on the remote Mac you can get the Computer and the Bonjour name of an IP in a two-step process by retrieving all hosts offering it with dns-sd -Z _nfs._tcp local (the example service here is NFS - other service names can be found here) and pinging all listed Bonjour names until you find the proper IP. As an GUI alternative you can use the Bonjour Browser.

In some cases you can get a name similar to the Bonjour name by entering smbutil status <IP>. The name is the NetBIOS name which is the "all-caps and without allmost all special characters" version of the Computer/Bonjour name.


In Terminal I would use arp

  • First make sure you have sent at least one packet to this machine using ping.

    $ ping -c 1 2.2.2.12
      PING 2.2.2.12 (2.2.2.12): 56 data bytes  
      64 bytes from 2.2.2.12: icmp_seq=0 ttl=255 time=0.981 ms  
    
  • Next arp that address.

    $ arp 2.2.2.12
      <host>.<domain> (2.2.2.12) at 0:1c:c4:f4:b8:c7 on en1 ifscope [ethernet]