Use nbtstat to return list of host names in IP range?

1

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.

adhoclobster

Posted 2014-12-11T18:19:35.123

Reputation: 111

Answers

0

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%
)

Squeezy

Posted 2014-12-11T18:19:35.123

Reputation: 5 930