Batch file checking if an website exist
Posted: 30 Mar 2012 10:50
I want a batch file to check if an website exist,and if it exist it has to say some text,and if it doesnt it has to do nothing.
A Forum all about DOS Batch
https://www.dostips.com/forum/
Code: Select all
>nul 2>&1 ping www.ed-dyreen.com &&echo.on-line ||echo.off-line
Code: Select all
::Copied from FAQ #153 by Timo Salmi with modifications.
@echo off & setlocal
:start
set ser=google.com
echo Checking WEB site by^
pinging %ser%
set ok_=true
ping -n 1 %ser%|find "Lost = 0">nul||set ok_=
if defined ok_ (
echo "Say some Text". Press the space bar. & echo^
"Say some Text" on %date% at %time%>>c:\ping_log1.txt
) else (
echo "Do Nothing" Press the space bar. & echo "Do Nothing" on %date% at %time%>>c:\ping_log1.txt
)
pause>nul
echo===============>>c:\ping_log1.txt
endlocal
Code: Select all
:: Script by Ed Dyreen with modifications.
:: source:http://www.dostips.com/forum/viewtopic.php?f=3&t=3142&sid=d2e10f5a5d0e2d6ea24bb705e98392c2
:: Orginal code ">nul 2>&1 ping www.ed-dyreen.com &&echo.on-line ||echo.off-line"
@echo off & Setlocal
:start
set /p ser=Press 1 for Google.com or 2 for wildblue.net then press Enter.
if %ser%==1 set ser=google.com
if %ser%==2 set ser=wildblue.net
echo Checking for active Internet Connection by^
pinging %ser%
>nul 2>&1 ping -n 1 %ser% &&goto connected ||goto n_connected
:connected
echo Active connection to %ser% & echo^
Active connection to %ser% on %date% at %time%>>c:\ping_log.txt
goto ans
:n_connected
echo NO Active connection to %ser% & echo^
No active connection to %ser% on %date% at %time%>>c:\ping_log.txt
goto ans
:ans
echo=======>>c:\ping_log.txt
set /p reply=Try again? Answer Y or N Case Sentisive:
if %reply%==Y goto :Y
if %reply%==N goto :N
echo You didn't do it right. Press the Space Bar.
pause>nul & cls & goto :ans
:Y
cls & goto start
:N
goto :eof
abc0502 wrote:the page is typing 404 file not found error is that mean it's an error to you ?
try this vb script
http://www.robvanderwoude.com/vbstech_internet_website.php
change the website in [ strWebsite = "www.robvanderwoude.com"] "2nd line in script" with your website
i tried that and it say it is up i don't know if that ok with you.
and ples answer the question i asked about the 404 error because there is a script but need changing so i need your answer
silent wrote:Like i can ping dostips.com but i cant ping dostips.com/forum,why ????
Code: Select all
@echo off
cls
Title Update Checker
REM Please Remember The Only Changes That Might be Done Wil be In The Variable Section
::===== LOGO =========================================::
echo:
echo:
echo:
echo:
echo:
echo:
echo:
echo:
echo: ###### #### ## ######## ## ## ########
echo: ## ## ## ## ## ### ## ##
echo: ## ## ## ## #### ## ##
echo: ###### ## ## ###### ## ## ## ##
echo: ## ## ## ## ## #### ##
echo: ## ## ## ## ## ## ### ##
echo: ###### #### ######## ######## ## ## ##
ping localhost -n 2 >nul
set "batch_file=%temp%\Search.bat"
set "vb_file=%temp%\download.vbs"
set "update_file=%temp%\update.txt"
::===== Variable ========================================::
set "ver_file=D:\ver.txt"
set "download_link=http://www.dreamwidth.org/stats/stats.txt"
Rem Change Both up Lines with your ver.txt directory and the link of update.txt
::===== Batch File =======================================::
>"%batch_file%" (
echo @echo off
echo cls
echo setlocal
echo for /f ^%%%%z in ^('findstr "update" "%update_file%"'^) do set comp1=^%%%%z
echo for /f ^%%%%y in ^('findstr "update" "%ver_file%"'^) do set comp2=^%%%%y
echo IF ^%%comp1%% EQU ^%%comp2%% ^( msg * There is no Update Available
echo ^) Else ^( msg * New Update is Available ^)
echo del /f /s /q "%vb_file%"
echo del /f /s /q "%batch_file%" )>>"%batch_file%"
echo del /f /s /q "%update_file%"
::===== VBScript ========================================::
>"%vb_file%" (
echo HTTPDownload "%download_link%", "%update_file%"
echo Sub HTTPDownload^( myURL, myPath ^)
echo Dim i, objFile, objFSO, objHTTP, strFile, strMsg
echo Const ForReading = 1, ForWriting = 2, ForAppending = 8
echo Set objFSO = CreateObject^( "Scripting.FileSystemObject" ^)
echo If objFSO.FolderExists^( myPath ^) Then
echo strFile = objFSO.BuildPath^( myPath, Mid^( myURL, InStrRev^( myURL, "/" ^) + 1 ^) ^)
echo ElseIf objFSO.FolderExists^( Left^( myPath, InStrRev^( myPath, "\" ^) - 1 ^) ^) Then
echo strFile = myPath
echo Else
echo WScript.Echo "ERROR: Target folder not found."
echo Exit Sub
echo End If
echo Set objFile = objFSO.OpenTextFile^( strFile, ForWriting, True ^)
echo Set objHTTP = CreateObject^( "WinHttp.WinHttpRequest.5.1" ^)
echo objHTTP.Open "GET", myURL, False
echo objHTTP.Send
echo For i = 1 To LenB^( objHTTP.ResponseBody ^)
echo objFile.Write Chr^( AscB^( MidB^( objHTTP.ResponseBody, i, 1 ^) ^) ^)
echo Next
echo objFile.Close^( ^)
echo Set oShell = CreateObject^("WSCript.shell"^)
echo sCmd = "%batch_file%"
echo oShell.Run sCmd, 0, False
echo End Sub )>>"%vb_file%"
Rem VBscript Original Source Code from: http://www.robvanderwoude.com/vbstech_internet_download.php
::===== Commands ======================================::
start /min %ComSpec% /c %vb_file% >nul
::===== End Batch =======================================::