Command to get IP address based on computer name

Luis Diaz
Luis Diaz used Ask the Experts™
on
Hello Experts,

I use
ping-a 

Open in new window

to get the IP address of a server.
I will like to find a command to do it the opposite. Enter the IP and get the primary computer name of the server.
I tried net stat and nslookup but it doesn’t work.
If you have a cmd or a powershell command to get this straightforward I am in.
Thank you very much for your help.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
FOXActive Directory/Exchange Engineer
Top Expert 2015

Commented:
If you have your dns set up correctly all you have to do is:
ping "ipaddress" -a

example:
ping 10.11.12.13 -a
JohnBusiness Consultant (Owner)
Most Valuable Expert 2012
Expert of the Year 2018

Commented:
Assuming this is on the same subnet, get Advanced IP Scanner (Famatech - free) and scan with that. It gives you this plus other information.
Sam JacobsDirector of Technology Development, IPM

Commented:
$hostName = ([System.Net.Dns]::gethostentry("IP Address")).HostName

Open in new window

Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Luis DiazIT consultant

Author

Commented:
Thank you Sam, this command is powershell or cmd?
Sam JacobsDirector of Technology Development, IPM

Commented:
PowerShell
Most Valuable Expert 2018
Distinguished Expert 2018
Commented:
This assumes you want to query machines in your own network. For external machines, if they don't have a PTR entry in the respective reverse lookup zone, there's nothing you can do.
If you don't get a response from nslookup, you don't seem to have a reverse lookup zone in your DNS, or the machine isn't registered there. In this case, other methods relying on DNS won't help, either.
For Windows target machines, you can try PowerShell and WMI:
(Get-WmiObject -Class Win32_ComputerSystem -ComputerName '192.168.1.1').Name

Open in new window

David FavorFractional CTO
Distinguished Expert 2018

Commented:
If I understand, I think this is what you're after...

# nslookup
> set q=ptr
> 66.70.203.106
Server:		127.0.0.1
Address:	127.0.0.1#53

Non-authoritative answer:
106.203.70.66.in-addr.arpa	name = mta1.joymta.com.

Open in new window

Luis DiazIT consultant

Author

Commented:
Ok, I was able to get my solution with ping the problem was that name server use an specific eur domain due to this the command doesn't work.  ping adrdressname.eur -a works!
David FavorFractional CTO
Distinguished Expert 2018

Commented:
Your question was about translating an IP to a host name.

The command you list above translates a host name to IP.

Confusing...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial