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.txtEXIT
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
if %state%==alive echo %4 is %state% >> E:\documents\z.txt
EXIT
Question: According to these lines, what happens if %state% is not alive?
it should look like 1.1.1.1 is Dead in the text file
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.txtTony
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?
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
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |