Where's my networking batches at?
April 24, 2010 7:17 AM

Windows networking and batch scripting help. Paging all windows command line gurus!

I need to write a script which can execute as a batch file on a Windows XP computer to discover the IP address, MAC address and NetBIOS names of all the devices on a subnet and save the results to a .txt file located on the desktop.

I am certain that should be possible with some combination of ARP, ping and netstat. However I am not certain how to get the script to execute these commands then move onto the next IP address in the subnet. I could probably get this to work on a linux machine or a mac but its been a long time since I have used windows in anger!

I am also familiar with the many executable programs that can do this too, but unfortunately it has to be a windows batch script. Oh and installing cgywin is not an option either.

Any help with this would be greatly received.
posted by gergtreble to Computers & Internet (5 answers total)
You would have to download programs, such as nmap to do this, which can be run from a CLI\bat file.

NMAP and NBTSCAN would do this.

Off the top of my head,

nmap -PR -oN [path-to-logfile] 192.168.0.0/24
nbtscan 192.168.0.0/24 > [path-to-logfile]
posted by Threeway Handshake at 8:04 AM on April 24, 2010


Cmd is capable of doing "for" loops in a batch file. I think this is what you need to investigate.
posted by dave*p at 9:37 AM on April 24, 2010


I'd recommend using vbscript and the Windows Scripting Host (cscript.exe or wscript.exe). Windows batch scripting is such a deficient language, and the support programs so lacking, that I don't know why anyone bothers to do anything complex in it.

Among other things, with vbscript you can access the WMI and do things like query the Win32_PingStatus object. I didn't find an object to inspect the ARP table, but you should also be able to use vbscript to run the command line program and parse the output after pinging the host.

No idea how to get the NetBIOS name. I could do it in Linux/OSX with smbclient installed, but I'm not aware of any command line interface for Windows that is similar. If you have administrator access on the machines you're scanning you can use WMI to connect to them and get the NetBIOS name... along with all sorts of other information.
posted by sbutler at 11:43 AM on April 24, 2010


Ok I think the nbtstat command in windows will do what I want that coupled with a "for" loop should sort it.

Thanks a lot.
posted by gergtreble at 7:29 PM on April 24, 2010


Just to let you know I went with this:

>> results.txt echo ****************************************************
>> results.txt echo * THE FOLLOWING HOSTS ARE RESPONDING TO PING *
>> results.txt echo ****************************************************
>> results.txt echo.
for /L %%x in (1,1,254) do echo 192.168.1.%%x & ping -n 1 -w 50 -i 6 192.168.1.%%x | find "Reply" && echo 192.168.1.%%x>> ~ip.txt
>> results.txt type ~ip.txt
>> results.txt echo.
>> results.txt echo ****************************************************
>> results.txt echo * NBTSTAT REPORTS THE FOLLOWING HOSTNAMES *
>> results.txt echo ****************************************************
>> results.txt echo.
for /f %%x in (~ip.txt) do echo %%x & echo %%x >> results.txt & nbtstat -A %%x | find "Registered" >> results.txt
>> results.txt echo.
>> results.txt echo ****************************************************
>> results.txt echo * NBTSTAT ALSO REPORTS THE FOLLOWING MAC ADDRESSES *
>> results.txt echo ****************************************************
>> results.txt echo.
for /f %%x in (~ip.txt) do echo %%x & echo %%x >> results.txt & nbtstat -A %%x | find "MAC Address" >> results.txt
del ~ip.txt


That does the job wonderfully. Thanks for the point in the right direction.
posted by gergtreble at 9:03 AM on April 25, 2010


« Older Rent-a-dog   |   How do you advance your freelance career at the... Newer »
This thread is closed to new comments.