Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi
I can ping xyz >> ping.txt to dump the contents into the file. I then want to query this file for a successfull ping and if so map a drive to that machine. Can someone tell me how to do this. I have tried to use the find command but cannot get it to generate an error level so it can progress.Thanks in advance
Lee

Find returns errorlevels 0, 1, 2
Try these, but WATCH for wrapped lines!:: pingnow.bat
@ECHO off
IF "%1"=="" ECHO IP address required
IF "%1"=="" GOTO end
:: Ascii assembler code by Herbert Kleebauer
ECHO
,8P_,FPZ0U]0U[,B0EWP_[SCYQ2M@I~E5@@O!A>%temp%.\echoit.com
TYPE nul >%temp%.\log.txt
SET cnt=:loop
SET cnt=%cnt%*
ECHO @PROMPT SET time=$t> %temp%.\gettim1.bat
%COMSPEC% /E:2048 /c %temp%.\gettim1.bat>
%temp%.\gettim2.bat
CALL %temp%.\gettim2.bat%temp%.\echoit.com %time% >>%temp%.\log.txt
PING -a -n 1 -s 1 %1 |FIND "Re" >>%temp%.\log.txt
IF errorlevel 1 ECHO Destination not reachable
IF not "%cnt%"=="*****" GOTO loop
SET cnt=
SET time=
DEL %temp%.\gettim2.bat
DEL %temp%.\echoit.com
TYPE %temp%.\log.txt
:end
:::: pingnow2.bat
@ECHO off
IF "%1"=="" ECHO IP address required
IF "%1"=="" GOTO end
:: Ascii assembler code by Herbert Kleebauer
PING -a -n 1 -s 1 %1 |FIND "Re" >nul
IF errorlevel 1 ECHO Destination not reachable
IF errorlevel 1 GOTO end
SET cnt=
TYPE nul >%temp%.\log.txt
TYPE nul >%temp%.\log.tmp
ECHO
,8P_,FPZ0U]0U[,B0EWP_[SCYQ2M@I~E5@@O!A>%temp%.\echoit.com
ECHO * * Press Q to quit * *:loop
SET cnt=%cnt%*
ECHO @PROMPT SET time=$t>%temp%.\gettim1.bat
%COMSPEC% /E:2048 /c %temp%.\gettim1.bat>
%temp%.\gettim2.bat
CALL %temp%.\gettim2.bat
%temp%.\echoit.com %time% > %temp%.\log.tmp
PING -a -n 1 -s 1 %1 |FIND "Re">> %temp%.\log.tmp
TYPE %temp%.\log.tmp >>%temp%.\log.txtTYPE %temp%.\log.tmp
IF "%cnt%"=="***********************" ECHO * *
Press Q to quit * *
IF "%cnt%"=="***********************" SET cnt=
CHOICE.COM /N /CQC /TC,1 >nul
IF errorlevel 2 GOTO loop
SET cnt=
SET time=
DEL %temp%.\gettim?.bat
DEL %temp%.\echoit.com
:end
::

Truely, my dear friend, that was a disgusting display of batch. I would do it this way:
@echo off
ping xyz>ping.txt
find "oåtkomlig" ping.txt>nul
if errorlevel 1 goto reachableecho Could not ping!
goto end
:reachableecho Could ping!
:endnote 1: I am unsure about how to map network drives for the moment. Replace the line "echo Could ping!" with whatever command is needed to map the network drive.
note 2: you shall also, of course, replaze "xyz" with the ip/name of the computer you are pinging.
note 3: the string "oåtkomlig" means unreachable in Swedish, which happens to be the language of my operating system. I think the English/American version of ping says "unreachable", but I am not sure about the exact words and such so you just replace "oåtkomlig" with any string that ping only outputs when it can't ping the computer.
Good luck.

![]() |
how to copy partition tab...
|
Ms dos
|

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