Page 1 of 1

Msdos command to check if a url with port is up and running.

Posted: 22 May 2013 00:55
by kidhaxman
I will create a script that generates a daily report of the status of a url.

For example: 170.211.215.7:53/mainhub/home

I could not ping this. Can anyone help me? I've had enough on google searching for answers. Y_Y

I monitor tomcat website. I need to check the whole URL and not just the port so I think telnet is not an option here.

Thanks in advance!

Re: Msdos command to check if a url with port is up and runn

Posted: 22 May 2013 01:01
by foxidrive
Is there an index.html at that URL?

Re: Msdos command to check if a url with port is up and runn

Posted: 22 May 2013 01:07
by kidhaxman
Some url on my list to monitor has .html extension.

Re: Msdos command to check if a url with port is up and runn

Posted: 22 May 2013 01:13
by foxidrive
Well - you can use WGET.EXE which is a free download and then use a batch file to see if the site is responding.

Code: Select all

@echo off
set target=http://170.211.215.7:53/mainhub/home
del tempfile.bin 2>nul
wget %target%/file.html --output-document=tempfile.bin
if exist tempfile.bin (
>>file.log echo %date% %time% - %target% is responding
) else (
>>file.log echo %date% %time% - %target% is NOT responding
)
del tempfile.bin 2>nul

Re: Msdos command to check if a url with port is up and runn

Posted: 22 May 2013 01:21
by kidhaxman
Wow thank you very much!

What about the url those without .html like 170.211.211.7:9087/web/guest

Re: Msdos command to check if a url with port is up and runn

Posted: 22 May 2013 01:47
by foxidrive
Pick a different file that is there. Smaller filesize is better.

Re: Msdos command to check if a url with port is up and runn

Posted: 22 May 2013 01:58
by foxidrive
I changed the code above - so you can change the file.html to another file and type and leave the tempfile.bin as it is.

Re: Msdos command to check if a url with port is up and runn

Posted: 22 May 2013 02:04
by kidhaxman
Sir fox not to be rude but I've been told that I'm not allowed to download that. Is there any other command to use for windows only?

Re: Msdos command to check if a url with port is up and runn

Posted: 22 May 2013 02:32
by foxidrive
You are referring to wget I assume. You can use this for HTTP connections that allow normal connections. It uses VB script under WSH which is default on at least Windows XP and higher.

Code: Select all

@echo off
set target=http://170.211.215.7:53/mainhub/home
set "file=index.html"

del "%file%" 2>nul

 >"%temp%\geturl.vbs" echo Set objArgs = WScript.Arguments
>>"%temp%\geturl.vbs" echo url = objArgs(0)
>>"%temp%\geturl.vbs" echo pix = objArgs(1)
>>"%temp%\geturl.vbs" echo With CreateObject("MSXML2.XMLHTTP")
>>"%temp%\geturl.vbs" echo .open "GET", url, False
>>"%temp%\geturl.vbs" echo .send
>>"%temp%\geturl.vbs" echo a = .ResponseBody
>>"%temp%\geturl.vbs" echo End With
>>"%temp%\geturl.vbs" echo With CreateObject("ADODB.Stream")
>>"%temp%\geturl.vbs" echo .Type = 1 'adTypeBinary
>>"%temp%\geturl.vbs" echo .Mode = 3 'adModeReadWrite
>>"%temp%\geturl.vbs" echo .Open
>>"%temp%\geturl.vbs" echo .Write a
>>"%temp%\geturl.vbs" echo .SaveToFile pix, 2 'adSaveCreateOverwrite
>>"%temp%\geturl.vbs" echo .Close
>>"%temp%\geturl.vbs" echo End With

cscript /nologo "%temp%\geturl.vbs" %target% %file% 2>nul

if exist "%file%" (
>>file.log echo %date% %time% - %target% is responding
) else (
>>file.log echo %date% %time% - %target% is NOT responding
)
del "%file%" 2>nul


Re: Msdos command to check if a url with port is up and runn

Posted: 22 May 2013 03:17
by kidhaxman
This is great! 1 Last thing. What is the best logic to loop this by read file line.

e.g input.txt contains different url line by line:

google.com
yahoo.com
facebook.com

Thanks!

Re: Msdos command to check if a url with port is up and runn

Posted: 22 May 2013 04:40
by foxidrive
We all hate it when the task is changed after providing working code. If you wanted a bunch of URLs in a text file then say so in the first post.

Often the code changes a lot with even minor changes in the task, and it is annoying to have to rewrite and test code *again*. </rant>

Re: Msdos command to check if a url with port is up and runn

Posted: 22 May 2013 23:58
by kidhaxman
Sorry bro I didn't meant to annoy you. I will try to work on it. Thank you very much!