Batch file to ping many pc names on network with leading zeros.

Posted on 2005-04-19
Last Modified: 2013-12-04
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.

Question by:CooperTupelo
    LVL 30

    Expert Comment

    Hi CooperTupelo,
    Check out the following link:

    Using the above free program you can ping computers in your local network.

    David Maisonave :-)
    LVL 86

    Accepted Solution

    >>I am trying to see if any PCs exist that are not in our records

    Well, then pinging all the names that *are* in your records does not seem to be the way to go . I'd suggest to

    net view

    on the command line and see whether there are PCs that are *not* named tw0001 - tw05**...

    Author Comment

    Thanks Axter, that program is pretty good.  JKR, is there anyway to pause the screen when running net view?  I tried using /p, like when using the dir command, but that does not work.
    LVL 86

    Expert Comment

    >>is there anyway to pause the screen when running net view?

    net view | more


    net view > all_machines.txt

    should help.

    Author Comment

    Yes, that is excellent.  This was my first question to post and I was not expecting responses this fast.  i am impressed.  Thanks both of you.
    LVL 30

    Expert Comment

    >>that program is pretty good.

    It's pretty good for a free program.  I used it to find all the computers in my local network that had a VNC server running.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
    For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now