I'm trying to resolve an IP like 192.168.204.194 to a computer name like "JohnsMac". I want to be able to get the local machine name for an internal IP I know.

What command will return the machine name in OS X?

link|improve this question

50% accept rate
feedback

2 Answers

What about nslookup?

#: nslookup 192.168.204.194

This requires that you have nslookup point to a DNS server that knows how to make this resolution. In my personal network, I use my dd-wrt router as a DNS relay and set it to resolve requests for hosts on the internal network (the 192.168.x.x net)

Is that what you're asking? The other thing I can think of is to edit the file located at:

#: /etc/hosts

You have to be root to edit it. Then you flush your dns cache by running:

#: sudo dscacheutil -flushcache

This will resolve IPs to hostnames and vice versa locally on your Mac, so no DNS server required. There are some big caveats to how this works though so read the man page for the hosts file:

#: man hosts

Since the 'nslookup' and 'host' commands ignore the hosts file, you have to use other commands to resolve using the hosts file, e.g.:

#: traceroute foo.com

or

#: dscacheutil -q host -a ip_address 1.2.3.4
link|improve this answer
feedback

In OS X Terminal, just ssh into the admin user.

Here are some example commands to use in the terminal, although there are multiple ways to ssh

ssh adminusername@IPADDRESS

or

ssh -l[root] IPADDRESS 

Here's an example of using this, with the output

ssh adminusername@172.xx.101.xxx

The authenticity of host '172.xx.101.xxx (172.xx.101.xxx)' can't be established.

RSA key fingerprint is d0:xx:27:xx:4b:xx:37:fb:xx:4a:4b:xx:2e:xx:ea:xx.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '172.xx.101.xxx' (RSA) to the list of known hosts.


Password: (ENTER PASSWORD HERE)

Last login: Fri Feb 24 12:32:49 2012 from 172.xx.101.xxx

x-surgeryCPU:~ cadmin$ 
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.