Batch file to ping many pc names on network with leading zeros.
Posted on 2005-04-19
I am currently an intern at a medium sized business that has about 550 PCs that have names ranging from tw0001 - tw05**. I want to write a batch file that will ping every possible name within the range of tw0001 - tw05**. I am trying to see if any PCs exist that are not in our records. This is what I have so far...
FOR /L %%i IN (1,1,550) DO PING -n 1 tw000%%i >> pingresults.txt
The problem with this is when %%i reaches 10, it starts pinging tw00010 where it should be tw0010. Is there anyway to force the variable
%%i to four digits filled with leading zeros? Also, is there anyway to limit the reults in the pingresults.txt to only those that fail? If neither of these are not possible, then c++ is my next option. I have not begun to write this in c++ yet but any suggetsions would be great. Thanks in advance.