In Windows 7 I'm using the command for /l %i in (1,1,254) do nbtstat -a xxx.xxx.xxx.%i to return host names based on a given IP range. But the output is so long and unfriendly. How could I improve it to return a list that looks more like a spreadsheet like:

IP address Host name MAC address xxx.xxx.xxx.1 host-name-01 xx-xx-xx-xx-xx-x1 xxx.xxx.xxx.2 host-name-02 xx-xx-xx-xx-xx-x2 xxx.xxx.xxx.3 host-name-03 xx-xx-xx-xx-xx-x3 ?

I've seen commands that have something like | list xxx at the end, but I'm not super-familiar with that particular syntax.


You may need to change "UNIQUE" to the local equivalent in the output.

@echo off
set PREFIX=127.0.0
setlocal enabledelayedexpansion

for /l %%i in (1,1,254) do ( 
nbtstat -a %PREFIX%.%%i > %TEMP%\info.txt 
for /F "tokens=4" %%a in ('findstr "MAC" %TEMP%\info.txt') do set MAC=%%a
for /F "tokens=1" %%a in ('findstr /R /C:"<00>  UNIQUE " %TEMP%\info.txt' ) do set HOSTNAME=%%a
echo %PREFIX%.%%i;%MAC%;%HOSTNAME%

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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