tags:

views:

655

answers:

2

Hi All,

I am working on a batch file to gather the mac addresses of two of my subnets clients however for some reason my batch file is not ending the first loop correctly, so the second loop is not being executed and thus the rest of the script is not being executed. Any ideas on why this is happening?

for /L %%i in (1,1,254) do ping.bat 192.168.232 %%i
for /L %%i in (1,1,254) do ping.bat 192.168.233 %%i
REM Some other stuff goes on here but the second loop never gets executed

Thanks a lot in advance

EDIT: ping.bat contains simply this:

nbtstat -A %1.%2

To get the MAC address via NetBIOS

A: 

Most probably it is waiting for the response from the other end. Didn't you try reducing the time out? I suggest you to add a dummy counter to check whether it is waiting for response or hanged.. :-)

Chathuranga Chandrasekara
I dont think it waits for the response from the other end because as soon as it pings x.x.x.254 the script ends its execution skipping the other commands in the batch file.
Can you pls add info about ping.bat?
Chathuranga Chandrasekara
+2  A: 

Starting a batch file aborts the "mother" batch file. Although she appears to finish the current line; your first FOR loop actually gets executed 254 times.

Adding a CALL statement would fix this:

for /L %%i in (1,1,254) do call ping.bat 192.168.232 %%i
for /L %%i in (1,1,254) do call ping.bat 192.168.233 %%i
echo Test complete!

Before the CALL statement was introduced, this was solved by running the child batch file in a new instance of the command interpreter:

for /L %%i in (1,1,254) do COMMAND /C ping.bat 192.168.232 %%i
Andomar
You can also simply use the command from ping.bat directly in the loop: do nbtstat -A 192.168.232.%%i
Joey