Batch file checking if an website exist
Moderator: DosItHelp
Batch file checking if an website exist
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.
Re: Batch file checking if an website exist
'
Code: Select all
>nul 2>&1 ping www.ed-dyreen.com &&echo.on-line ||echo.off-line
Re: Batch file checking if an website exist
Greetings Silent,
I really like Ed Dyreen's solution. I think I'll start using his script.
Anyway, I currently use something similar to the script below on
a daily basis. I like to echo the results to the screen as well as
create a log file.
Best wishes!
I really like Ed Dyreen's solution. I think I'll start using his script.
Anyway, I currently use something similar to the script below on
a daily basis. I like to echo the results to the screen as well as
create a log file.
Best wishes!
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
Re: Batch file checking if an website exist
Greetings Ed,
I added a few lines to your code for my use on a daily basis.
Thank you and a tip of the fedora!
I added a few lines to your code for my use on a daily basis.
Thank you and a tip of the fedora!
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
Re: Batch file checking if an website exist
Guys i need your help,both codes work great,but i want to ping a topic on a website,why it doesnt works ? Always tells me off-line.I want to use it in the game,and it has to check if a topic called "update 2.0" exist, so i want to ping a address like : http://www.website.com/download/update-2.0-f9.html
Like i can ping dostips.com but i cant ping dostips.com/forum,why ????
Thanks in advance,
Like i can ping dostips.com but i cant ping dostips.com/forum,why ????
Thanks in advance,
Re: Batch file checking if an website exist
That is not how ping works.
You would need to use a 3rd party utility or some other scripting language to do that.
wget would be an option.
You would need to use a 3rd party utility or some other scripting language to do that.
wget would be an option.
Re: Batch file checking if an website exist
I dont want the batch file to download the update,but alert that new update is avaiable and this game is outdated.There is no way to ping some topic like the example i gave ?
Re: Batch file checking if an website exist
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
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
Re: Batch file checking if an website exist
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
404 where ? The page i have posted is a fake one
PS,the vbs u gave says the site is down 2 Well,i can make a free website on some shit server for each update and it would just ping the normal addres (like,www.funkydunky.freehost.org)
The website of my game is www.codealphazero.freeforums.org
(Yeah long as shit)
Re: Batch file checking if an website exist
i looked at this URL: http://codealphazero.freeforums.org/test-for-update-t9.html
so basically u want to see if a link in this page is exist or not?
is that it
if so is the link you will provide will be from a permanent website host like mediafire or any host like it ?
so basically u want to see if a link in this page is exist or not?
is that it
if so is the link you will provide will be from a permanent website host like mediafire or any host like it ?
Re: Batch file checking if an website exist
Wat ? i want to check if the link that you checked exist,and the file will be uploaded as a attachment.
Re: Batch file checking if an website exist
are you the one who will upload the update?
if so i have an easy idea
if so i have an easy idea
Re: Batch file checking if an website exist
silent wrote:Like i can ping dostips.com but i cant ping dostips.com/forum,why ????
Ping checks a server on a domain, not a page on a server.
Use wget as suggested to download the html page. If Wget returns an error then the page isn't there.
It doesn't download the attachment unless you tell it to, with switches.
Re: Batch file checking if an website exist
abc,what is that idea ?
Re: Batch file checking if an website exist
Here is the batch but first you must READ THIS:
Requirement:
1- Always include a text file in all of your updates name it "ver.txt" you will write in it the version of the update in this format "update-x.x". without qoutes. "x mean numbers"
2- A direct link on your website take that form "http://website/what-ever-directory/update.txt"
this file will be updated with the latest version of the update file in this form "update-x.x"
like the "ver.txt" file.
basicaly every time u make update put a ver.txt with the update and put update.txt in your website write in both of them this word "update-x.x" numbers must be the same.
so when a user have old update and the website have new one when the batch work it will download the update.txt from your site and comapare the version with the ver.txt file if it is the same it will pop-up a message saying there is no update available and if it doesn't match it say there is new update available.
Now the Batch:
Notes:
1- Change the Variable Section Only and all variable in the batch will be set.
2- The link make sure it start with "http://" because it give errors some times.
3- Make sure the link is always the same doesn't change and so is the ver.txt file.
4- Make sure there is no spaces between "update" and "-" and "version number".
I tested this patch with this link: http://www.dreamwidth.org/stats/stats.txt and this location of the "ver.txt" D:\ver.txt and it work fine with me.
I hope it help.
Requirement:
1- Always include a text file in all of your updates name it "ver.txt" you will write in it the version of the update in this format "update-x.x". without qoutes. "x mean numbers"
2- A direct link on your website take that form "http://website/what-ever-directory/update.txt"
this file will be updated with the latest version of the update file in this form "update-x.x"
like the "ver.txt" file.
basicaly every time u make update put a ver.txt with the update and put update.txt in your website write in both of them this word "update-x.x" numbers must be the same.
so when a user have old update and the website have new one when the batch work it will download the update.txt from your site and comapare the version with the ver.txt file if it is the same it will pop-up a message saying there is no update available and if it doesn't match it say there is new update available.
Now the Batch:
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 =======================================::
Notes:
1- Change the Variable Section Only and all variable in the batch will be set.
2- The link make sure it start with "http://" because it give errors some times.
3- Make sure the link is always the same doesn't change and so is the ver.txt file.
4- Make sure there is no spaces between "update" and "-" and "version number".
I tested this patch with this link: http://www.dreamwidth.org/stats/stats.txt and this location of the "ver.txt" D:\ver.txt and it work fine with me.
I hope it help.