Batch File to test connectivity

TechieSooner

Supreme [H]ardness
Joined
Nov 7, 2007
Messages
7,601
Code:
@ECHO OFF
ping 192.168.0.2 | find "Reply" /c > log.txt
del log.txt
if log.txt==4 ECHO SYNCTOY
PAUSE

I basically want this to say "If the ping works- run SyncToy".

Don't know how I can do this.

All the ping/find command does is output the number 4 if I get 4 replies- so that's something to validate against.

However- how do I validate against that??? I thought an "if EXIST log.txt ECHO SYNCTOY" but the problem with that is even if the ping fails, a file still gets created.

Any ideas/suggestions on how to do this?
 
The code below works.
Enter the target IP after the batch file name (or you can hard code it).

Here's how it works:

C:\test>reply_test 192.168.55.1
IP Replied!

C:\test>reply_test 192.168.55.2
No Reply on that IP!




@echo off
ping /n 1 %1 | find "Reply" >nul
if %errorlevel% == 0 goto reply
@echo No Reply on that IP!
goto end
:reply
@echo IP Replied!
:end
 
The code below works.
Enter the target IP after the batch file name (or you can hard code it).

Here's how it works:

C:\test>reply_test 192.168.55.1
IP Replied!

C:\test>reply_test 192.168.55.2
No Reply on that IP!




@echo off
ping /n 1 %1 | find "Reply" >nul
if %errorlevel% == 0 goto reply
@echo No Reply on that IP!
goto end
:reply
@echo IP Replied!
:end

That's how I do it in bash too. Except you can rely on the errorlevel from ping instead of testing for "Reply" or "TTL".
 
That's how I do it in bash too. Except you can rely on the errorlevel from ping instead of testing for "Reply" or "TTL".

Yep, good point.

This simplified code works too:


@echo off
ping /n 1 %1 >nul
if %errorlevel% == 0 goto reply
@echo No Reply on that IP!
goto end
:reply
@echo IP Replied!
:end
 
Back
Top