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.
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.
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.
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
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.
For many IP addresses you could just use ping -a, for example
will return
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:
NSLOOKUP
errors you have to use2^>NUL
instead of1^>NUL
FINDSTR /C
to extract the value after the four whitespace characters. As the four spaces only seem to exist for theName:
entry, this appears to be only way to make it work on other localized systems.psexec \192.168.0.65 hostname
DMHD006 hostname exited on 192.168.0.65 with error code 0.
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