Solved Help With Ping Batch

May 21, 2012 at 07:45:27
Specs: Windows XP
I made a batch file that will ping host IPs from a text file and then put the results of the ping in a separate file called z.txt. I am having trouble getting the results file to show up. It will be created if i scan one UP host but it will not be created if the host is down. Also I modded this batch from a coworker for my scan. Can someone help me understand what the commands do as well as what may be the problem. Thanks. Here is the batch.


@echo off
if exist E:\documents\fwiplist12.txt goto Label1
echo.
echo Cannot find E:\documents\fwiplist12.txt
echo.
Pause
goto :eof

:Label1
for /f %%i in (E:\documents\fwiplist12.txt) do call :Sub %%i
goto :eof

:Sub
set state=alive
ping -n 4 %4 | find /i "bytes=" || set state=dead
if %state%==alive echo %4 is %state% >> E:\documents\z.txt

EXIT


See More: Help With Ping Batch

Report •


✔ Best Answer
May 22, 2012 at 08:51:54
I figured it out.

@echo off
if exist c:\fwiplist.txt goto Label1
echo.
echo Cannot find c:\fwiplist.txt
echo.
Pause
goto :eof

:Label1
for /f %%i in (c:\fwiplist.txt) do call :Sub %%i
goto :eof

:Sub
set state=alive
ping -n 1 %1 | find /i "bytes=" || set state=dead
if %state%==alive echo %1 is %state% >> c:\results.txt
if %state%==dead echo %1 is %state% >> c:\results.txt



#1
May 21, 2012 at 09:09:50
if %state%==alive echo %4 is %state% >> E:\documents\z.txt
EXIT

Question: According to these lines, what happens if %state% is not alive?

How To Ask Questions The Smart Way


Report •

#2
May 21, 2012 at 09:23:29
it should look like 1.1.1.1 is Dead in the text file

Report •

#3
May 21, 2012 at 13:50:55
You aren't doing anything with the state if the host isn't alive. No point in checking the state with IF, just echo it out.

echo %4 is %state% >> E:\documents\z.txt

Tony


Report •

Related Solutions

#4
May 21, 2012 at 14:28:06
juicyjon: it should
That ain't what I asked.

How To Ask Questions The Smart Way


Report •

#5
May 22, 2012 at 07:30:47
what I am trying to do is ping hosts on the network and then have a results text file with either 1.1.1.1 is alive or 1.1.1.1 is dead. When i run this batch it will sometime come back with the error "process tried to write to nonexistent pipe" and that error will not stop until i hit ctrl c to stop it. What would cause this?

Report •

#6
May 22, 2012 at 08:51:54
✔ Best Answer
I figured it out.

@echo off
if exist c:\fwiplist.txt goto Label1
echo.
echo Cannot find c:\fwiplist.txt
echo.
Pause
goto :eof

:Label1
for /f %%i in (c:\fwiplist.txt) do call :Sub %%i
goto :eof

:Sub
set state=alive
ping -n 1 %1 | find /i "bytes=" || set state=dead
if %state%==alive echo %1 is %state% >> c:\results.txt
if %state%==dead echo %1 is %state% >> c:\results.txt


Report •

#7
May 24, 2012 at 09:47:29
exactly :)

mike


Report •

Ask Question