I'm looking for a command line tool which gets an IP address and returns the host name, for Windows.


The command you are looking for is called nslookup, works fine for reverse lookups IFF someone has configured a reverse zone file, which they don't always do.


if all the above fails, and you are specifically looking for a Windows machine, you can use

nbtstat -a

The data returned will be all the NetBIOS records the machine has. The one with a <20h> record type will usually be the machine's name.

  • 3
    Not working when connected through the open vpn – Alexander.Iljushkin Apr 5 '16 at 6:13
  • @Flextra - you will need SMB access to the machine. Your VPN may be blocking it. – Moose Apr 7 '16 at 2:55
  • Interesting, looks like it tacks on the fully qualified domain name in the formatting: Pinging NETBIOSNAME.DOMAINNAME.com [xxx.xxx.xxx.xxx]. If its on the network and not on the domain (for me a unix system of interest) then ping -a just formats with the ipaddress alone it looks like. – jxramos Feb 6 '17 at 21:12
  • Works for me. Just what I needed! – FearlessFuture Apr 12 '18 at 14:13
  • 1
    I keep getting Host not found. any idea why? – Shayan Nov 24 '19 at 19:22

For many IP addresses you could just use ping -a, for example

ping -a

will return

Pinging ww-in-f106.google.com [] with 32 bytes of data:

Reply from
  • 2
    This is what I always use first as it is universally available on pretty much every machine. – Goyuix Oct 13 '09 at 14:54
  • 15
    ping is sooo often used to do simple DNS lookups... sigh don't do that. – PEra Oct 13 '09 at 16:48
  • 4
    this is the only answer that got me the hostname from my raspberry in my LAN. @PEra why is this a bad answer? – andy Sep 18 '19 at 20:52
  • How does this works? Though which protocol? – BAKE ZQ May 16 '20 at 11:57

If you use nslookup command with the IP address as its first argument will return the PTR record (the reverse entry) if it exists. For example:


Use dig. A Windows port is available from the ISC here (look in the immediate download box for the link to the zip file). Here's their man page reference for dig.

Ward's point about the reverse lookup records often not getting created is very much true. Reverse lookups often do fail because many admins don't bother creating the ptr records.


(tested under Windows 10 x64)

From command line:

FOR /F "tokens=2 delims= " %A in ('2^>NUL NSLOOKUP "%IP_ADDRESS%" ^| FINDSTR /C:": "') do ECHO %A

Within a script:

FOR /F "tokens=2 delims= " %%A in ('2^>NUL NSLOOKUP "%IP_ADDRESS%" ^| FINDSTR /C:": "') do ECHO %%A

Two (side)notes:

  • To supress NSLOOKUP errors you have to use 2^>NUL instead of 1^>NUL
  • I've used FINDSTR /C to extract the value after the four whitespace characters. As the four spaces only seem to exist for the Name: entry, this appears to be only way to make it work on other localized systems.

psexec \ hostname

DMHD006 hostname exited on with error code 0.

  • 1
    Keep in mind that the configured hostname not necessarily matches the hostname that is configured in DNS. – Gerald Schneider Jul 25 '19 at 8:44

if you want to know the host-name in same network then please use another machine which have same network and use below commend
Ping -an ip addres

  • 4
    Didn't you notice this answer was already here? – and it's not designed for this. – Esa Jokinen Jun 28 '17 at 5:36

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