Getting List of Host Names in the Subnet – Windows
November 5, 2010 Leave a comment
Getting List of Host Names in the Subnet – Windows
Introduction:
Identifying host name associated with IP Address in Windows is simple work. So here am going to demonstrate how to get multiple host names which are available in the same subnet.
How we can do it:
Usually we can get the Host name associated with the IP address using the following command.
NBTSTAT -a [Computer IP Address]
The Above given command will return the HOST NAME associated with the IP address given.
Mixing it With DOS Batch Script:
By Mixing this command with DOS Batch script we can get multiple Host names available in the SubNet.
For Loop in DOS Script:
FOR /L %%varaible IN ( START STEP END) DO COMMAND
%%Variable is the Name of the variable
START- Start value for the FOR Loop
STEP- Step value for the FOR Loop
END- End value for the FOR Loop
COMMAND- Command to execute multiple times
Putting it Together:
Save the following code in a file with .BAT extension
FOR /L %%A IN (0 1 255) DO NBTSTAT -A "192.168.1.%%A">>File.txt
Running the program
So now run the bat file and see the File.txt in the current directory of Bat file it will contain details of the Host names in the SubNet