I'm looking for a command line tool which gets an IP address and returns the host name, for Windows.
(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
- To supress
NSLOOKUPerrors you have to use
- I've used
FINDSTR /Cto 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.
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.