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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
kidhaxman
Posts: 10
Joined: 16 Jan 2013 00:48

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

#1 Post by kidhaxman » 22 May 2013 00:55

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!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#2 Post by foxidrive » 22 May 2013 01:01

Is there an index.html at that URL?

kidhaxman
Posts: 10
Joined: 16 Jan 2013 00:48

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

#3 Post by kidhaxman » 22 May 2013 01:07

Some url on my list to monitor has .html extension.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#4 Post by foxidrive » 22 May 2013 01:13

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

kidhaxman
Posts: 10
Joined: 16 Jan 2013 00:48

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

#5 Post by kidhaxman » 22 May 2013 01:21

Wow thank you very much!

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#6 Post by foxidrive » 22 May 2013 01:47

Pick a different file that is there. Smaller filesize is better.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#7 Post by foxidrive » 22 May 2013 01:58

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.

kidhaxman
Posts: 10
Joined: 16 Jan 2013 00:48

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

#8 Post by kidhaxman » 22 May 2013 02:04

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?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#9 Post by foxidrive » 22 May 2013 02:32

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


kidhaxman
Posts: 10
Joined: 16 Jan 2013 00:48

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

#10 Post by kidhaxman » 22 May 2013 03:17

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!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

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

#11 Post by foxidrive » 22 May 2013 04:40

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>

kidhaxman
Posts: 10
Joined: 16 Jan 2013 00:48

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

#12 Post by kidhaxman » 22 May 2013 23:58

Sorry bro I didn't meant to annoy you. I will try to work on it. Thank you very much!

Post Reply