How to Check Whether a Website Is Up

2012-01-11 @ admin

So one of my users asked me a question today:

I’d like to programmatically check whether a web server is running. The server is not running on the same IBM i system as my program, so I need to check it across a network. I’ve tried using PING, but sometimes the server is down, and PING doesn’t detect it. How can I check the web server across a network?

Here we go…

In this article, I provide a utility in the form of a CL command named Check TCP Server (CHKTCPSVR) that attempts to check whether a TCP server is running. It works by making a TCP connection over a network to see whether there’s a program responding on a given TCP port number. The CHKTCPSVR utility can check a web server, but it can also check other servers, such as Telnet, SMTP, SSH, or POP3, based on the port specified.

If there’s no TCP server running on the port, CHKTCPSVR returns an error message. Otherwise, it assumes that if a valid connection could be established, the server must be up. So it disconnects and reports success to your application.

Here’s what the CHKTCPSVR command looks like if you prompt it:

It’s intended to be used from a CL program like this:

PGM
CHKTCPSVR HOST(www.stripesbook.com) PORT(80)
MONMSG MSGID(CPF0000 CPE0000) DO
SNDMSG MSG('www.stripesbook.com is down!')
TOUSR(SCOTTK)
ENDDO
ENDPGM

In that example, I used SNDMSG to send myself a message, but you could easily switch it out with any other type of notification that you want, then load it into the job scheduler and have it run at regular intervals. That way, if a server goes down, it lets you know.

Or you can use check web server servise.

Purchase "The Stripes Book" now

Comments