Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi all, im trying to write a bat file that will keep pinging a ip address lets say 10.174.10.48. if the ping fail then it will run another bat file eg restart.bat..
can anyone help me will the codes.. thx

How about a one-liner:
ping -n 1 10.174.10.48 | find "unreachable" >nul && call restart.bat
The above will do the check once. It can be put in a loop if you want.

hi all, anyway to keep pinging the IP address and if ping fails run file.exe, wait for the exe to complete running then start pinging again??
thx alot

@echo off
setLocal EnableDelayedExpansion:loop
ping 10.174.10.48 | find /i "reply" > nul
if errorlevel 1 file.exe
ping 1.1.1.1 -n 1 -w 60000 > nul
goto :loop
=====================================
If at first you don't succeed, you're about average.M2

Hi M2, is it possible to change the codes to if ping is getting "Request timed out" for 10 continuous times then run the exe file..
thx again

@echo off
setLocal EnableDelayedExpansion:loop
for /f "tokens=* delims= " %%i in ('ping 10.174.10.48 ^| find /i "Request timed out"') do (
set /a bad+=1
echo bad count is !bad!
)
if !bad! geq 10 file.exe
ping 1.1.1.1 -n 1 -w 6000 > nul
goto :loop
=====================================
If at first you don't succeed, you're about average.M2

hi M2, is is possible to reset the bad count to 0 when there is a reply from the ping? the code that u written will count all "Request timed out" even if there is a reply from ping in between the "Request timed out".
i need to count for :"Request timed out"
"Request timed out"
"Request timed out"
"Request timed out"
"Request timed out"
"Request timed out"
"Request timed out"
"Request timed out"
"Request timed out"
"Request timed out"then run the file.exe
thx

@echo off
setLocal EnableDelayedExpansion:loop
ping -n 2 10.174.10.48 >> log
find /i "Reply" < log > nul
if not errorlevel 1 type nul > log & goto :loopfor /f "tokens=1" %%a in ('find /c /i "Request timed out" ^< log') do (
if %%a geq 10 echo file.exe && type nul > log
)
goto :loop
=====================================
If at first you don't succeed, you're about average.M2

hi can any one help me pleas
i want to ping many ip and save them to text file then send them by mail in a batch file.
thanks
this is working but i want to add many ip:
@echo off
setLocal EnableDelayedExpansion
:loop
ping -n 2 192.168.100.1 >> log.txt
find /i "Reply" < log.txt >
if not errorlevel 1 type nul > log.txt & goto :loop
for /f "tokens=1" %%a in ('find /c /i "Request timed out" ^< log.txt') do (
if %%a geq 10 echo file.exe && type nul > log.txt
)
goto :loop

Do you want to check each one in a list ONCE then go through the list agin until ONE or ALL trigger at 10?
BTW: is this meant to have a file name after > ?
find /i "Reply" < log.txt >
=====================================
If at first you don't succeed, you're about average.M2

i have a problem with network cables i don't know wen it is plugged or not.and i have 25 computers so i want a bat file to ping all ip that i well enter and wen he well finish the ping save the result to .txt file then send them by outlook to some email . so can you help me pleas

This wil create a log but I don't know how to script outlook.
::==================================
for /f "tokens=* delims= " %%a in (IPlist) do (
ping %%a >> pinglog
)
=====================================
If at first you don't succeed, you're about average.M2

thank youuuuuuuu
you have helped me very much.and pleas if you or some one find out how to send a text file by outlook or e-mail tell me pleassssss
thanks again

You can get a command line mailto here:
http://golden-triangle.com/MAILTO.ZIP
=====================================
If at first you don't succeed, you're about average.M2

hi Mechanix2Go,
sorry to bother you again but just i am wandering how can i save only the "Request timed out" in the .txt file.
thanks for helping

::==================================
for /f "tokens=* delims= " %%a in (IPlist) do (
ping %%a | find "Request timed out" >> pinglog
)
=====================================
If at first you don't succeed, you're about average.M2

HI Mechanix2Go,
help me pleasssi have tried this but she didn't work
@echo off
setLocal EnableDelayedExpansion
:loop
ping -n 2 192.168.100.1 >> log.txt
ping -n 2 192.168.100.2 >> log.txt
ping -n 2 192.168.100.3 >> log.txt
find /i "Reply" < log.txt >
if not errorlevel 1 type nul > log.txt & goto :loop
for /f "tokens=1" %%a in ('find /c /i "Request timed out" ^< log.txt') do (
if %%a geq 10 echo file.exe && type nul > log.txt
)
for /f "tokens=* delims= " %%a in (IPlist) do (
ping %%a | find "Request timed out" >> pinglog.txt
)
MAILTO.exe -v sender -d admin -at log.txt -n test@hotmail.com
i know this is not right
so pleas help me

Are you getting the expected logs?
The loops? or what?
=====================================
If at first you don't succeed, you're about average.M2

@echo off
setLocal EnableDelayedExpansion
:loop
ping -n 2 192.168.100.1 >> log.txt
ping -n 2 192.168.100.2 >> log.txt
ping -n 2 192.168.100.3 >> log.txt
find /i "Reply" < log.txt >
if not errorlevel 1 type nul > log.txt & goto :loopfor /f "tokens=* delims= " %%a in (IPlist) do (
ping %%a | find "Request timed out" >> pinglog.txt
)
she didn't work ??
i want to ping all my ip and only the Request timed out save them to the .txt file

Then you use the FIND after the ping.
=====================================
If at first you don't succeed, you're about average.M2

Dear mechanix2go.
if you pleas can you give me the complete bat file code to this:
i want to ping all IP that i have entered in the txt and only the "Request timed out" save them to the .txt file
Best regard

@goto :start
Hi,
This thread has had a few twists and has gotten confusing.
if what you need is to ping a lisy and log only those which timed out,
try the code below. If it's more complex, you may want to start a new thread.::===========================================
:start
@echo off
setLocal EnableDelayedExpansionfor /f "tokens=* delims= " %%a in (IPlist) do (
echo ================================ >> timedout.txt
echo %%a >> timedout.txt
ping %%a | find "Request timed out" >> timedout.txt
)
=====================================
If at first you don't succeed, you're about average.M2

Hi mechamix2go,
i have run this :
:start
@echo off
setLocal EnableDelayedExpansion
ping -n 2 192.168.100.101 >> timedout.txt
ping -n 2 192.168.100.140 >> timedout.txt
for /f "tokens=* delims= " %%a in (IPlist) do (
echo ================================ >> timedout.txt
echo %%a >> timedout.txt
ping %%a | find "Request timed out" >> timedout.txt
)
the result is :*Pinging 192.168.100.101 with 32 bytes of data:
Reply from 192.168.100.101: bytes=32 time<1ms TTL=128
Reply from 192.168.100.101: bytes=32 time<1ms TTL=128
Ping statistics for 192.168.100.101:
Packets: Sent = 2, Received = 2, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms*Pinging 192.168.100.140 with 32 bytes of data:
Request timed out.
Request timed out.
Ping statistics for 192.168.100.140:
Packets: Sent = 2, Received = 0, Lost = 2 (100% loss),what is wrong???

These 2 lines put the result into timedout.txt regardless of what they are.
Don't you want to put the IPs into a file called IPlist?
If not and you just want to specify these 2:
::============================================
ping -n 2 192.168.100.101 | find "Request timed out" >> timedout.txt
ping -n 2 192.168.100.140 | find "Request timed out" >> timedout.txt
::==============================Sorry this is not more clear. I may be going out shortly but I'll get back to you and work with you til it's solved.
=====================================
If at first you don't succeed, you're about average.M2

hi mechamix2go,
you are Genius :)
thanks i have understand now its working ,
like i told you i have 25 POS computers and every day i synchronize sales now i can find out for sure if the sales is correct.
now i have add it to the Scheduled Tasks in control panel at morning but i have see that the batch file modify and add the new ping in the timedout.txt .
if i want to automatically rename the result 'timedout.txt' to the date that i have run the batch file.
or 'export the result to the date that i have run the bat file.'
can you pleas help me with this? :$

Do this and post result:
echo %date%
=====================================
If at first you don't succeed, you're about average.M2

hi mechmix2go,
where i want to put "echo %date%"??
coz this only show me the date.
when the batch file export the .txt file i want to name it with the curent date .
example:
if today is 22/07/2008
the name of the .txt file be 22.07.2008.txt
or 22072008.txt .
can bat file do it??
thanks
best regard
LEO.

Leo,
I think M2 simply wants you to type echo %date% at the command prompt and post the resulting output. This may seem silly, but it is because everyone's %date% variable may produce differently formatted output, depending on which country they are in. For example, it could be 22/7/08, 22/07/2008, 7/22/2008, 2008-07-22 etc.
(Just answering for M2 to speed things up in case it's currently night-time in M2's time zone. Apologies if I'm interfering.)

thank you all now its working very good this is the source code :
:start
@echo off
setLocal EnableDelayedExpansion
echo %date%
for /f "tokens=* delims= " %%a in (IPlist) do (
echo ================================ >> %date%
echo %%a >> %date%
ping %%a | find "Request timed out" >> %date%
)Best Regard,
LEO

hi sagven55,
this is the the final source code.
but if you want 25 computer you must enter there IPs in text file named 'iplist' like:192.168.100.1
192.168.100.2
192.168.100.3
then save it@echo off
setLocal EnableDelayedExpansion
echo %date%
for /f "tokens=* delims= " %%a in (IPlist) do (
echo ================================ >> %date%
echo %%a >> %date%
ping %%a | find "Request timed out" >> %date%
)this is all ;-)

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |