There are two ways to do this. (1.) Telnet to the host on port 80. (Net::Telnet) If connection is refused, then there is no HTTP server running or DOWN, else HTTP server is running or UP.
(2.) Perform a HTTP request to the server NOT for specific content but for Server Side Status info. I dont believe there is a specific method in LWP that returns a YES or NO answer on whether or not the server is running. But there are methods in LWP for getting server header information on a HEAD request for "http://hostname". You can do this in LWP with the following code. It will return the following data if the server is UP: _protocol: HTTP/1.1 _content: _headers: HTTP::Headers=HASH(0x828a9b0) _rc: 200 _msg: OK And if the server is DOWN, it will return: _request: HTTP::Request=HASH(0x816c078) _content: _headers: HTTP::Headers=HASH(0x826db30) _rc: 500 _msg: Can't connect to 64.75.173.18:80 (Socket is not connected) Here is the Code: #!/usr/bin/perl use LWP::UserAgent; my $ua = LWP::UserAgent->new(env_proxy => 1, keep_alive => 1, timeout => 30, ); $request = HTTP::Request->new('HEAD', 'http://www.essenz.com/'); $r = $ua->request($request); %b = %{$r}; foreach $key (keys(%b)) { print "$key: $b{$key}\n"; } Let me know if this helps. John Von Essen On Wed, 30 Oct 2002, Raghu Karamel wrote: > Hi > > I have a stupid question. Hope that it won't be so hard to answer. > > I would like to verify the state of the web server (UP or DOWN) before I make an >HTTP request to the web sever. Is there a method available in LWP that allows me to >do this? Or what is the best way to do this? > > I asked this question few minutes back, But I wasn't sure whether I posted it or >not. Please ignore this email if you got the previous one. > > Thanks, Raghu >
