Author |
Topic  |
|
Sebastian
Starting Member
4 Posts |
Posted - 30 June 2001 : 09:11:57
|
I would like to make a page on my website that displays if a certain other computer is online or not. That other computer has a constant IP, and all I want to know if it is online or not.
I have seen ASP pages that do such a thing, but I have no idea how.
Any advise would be very welcome 
Thanks
|
|
aspdesigner
Junior Member
 
165 Posts |
Posted - 30 June 2001 : 22:14:34
|
We all were talking about whether it was even possible to do this from NT without using a DLL or component back late last year. I posted a working program to demonstrate how you could do this back in December?, but I just tried to do a search for it and I couldn't find it any more.
So here is a little program that will show you how to do what want -
<script language="PerlScript" RUNAT=SERVER> sub CheckURLPerl(\$){ use LWP::Simple; my ($URL) = @_; if (head($URL)) {return true;} else {return false}; } </script>
<% function CheckURL(MyURL) if (LCase(Left(MyURL,7)) <> "http://") then MyURL = "http://" & MyURL if (CheckURLPerl(MyURL)) then CheckURL = "[" & MyURL & "] is Available<P>" else CheckURL = "Problem with accessing [" & MyURL & "]<P>" end if end function %>
Test of using PerlScript / ASP Combo to Check if a web page in available...<BR> by aspdesigner (<A HREF="mailto:webmaster@arlingtonmall.com">webmaster@arlingtonmall.com</A>)<HR> <FORM ACTION="CheckURL.asp"> Enter Web Page to Check: <INPUT TYPE="text" NAME="pageURL"> <INPUT TYPE="Submit" VALUE="Go Check It!"> </FORM> <P> <% If request("pageURL") <> "" then response.write CheckURL(request("pageURL"))%> <HR>End of Test
This uses a combination of PERLScript and VBScript interfaced with each other in the same program! The PERLScript routine uses part of the LWP library to have your server attempt to access another web site via an HTTP HEAD request. By using a HEAD request rather than a GET, it also makes this script more efficient, as you do not have to transfer the entire web page just to see if the site is up or not!
Be very careful changing the code. I had to do some weird things to handle the differences between how PERLScript and VBScript interpret certain variable types and conditions to make this work.
The only requirement is that your server have ASPPerl support installed. The better NT hosting companies do, but don't expect this to work on one of those "free" hosting outfits. If you get an error message like "unsupported language", you know what the problem is.
Along with this one, I also wrote a program that could access any other web site, and suck the contents into a VBScript variable! Let me know if you are interested, I can provide this as well. 
Edited by - aspdesigner on 30 June 2001 22:17:35 |
 |
|
redbrad0
Advanced Member
    
USA
3725 Posts |
Posted - 01 July 2001 : 12:20:26
|
i got this error message when running this script
Invoking main::CheckURLPerl error '80004005'
Can't call method "abs" on an undefined value at D:/Perl/site/lib/HTTP/Request.pm line 107.
/check_if_webpage_is_running.asp, line 0 error '80004005'
Unspecified error
/check_if_webpage_is_running.asp, line 13
Brad |
 |
|
HuwR
Forum Admin
    
United Kingdom
20587 Posts |
Posted - 01 July 2001 : 13:42:49
|
you could try this simpler version, you pass it a url like
http_asp.asp?url=www.myurl.com
<html> <HEAD>
<script language="PerlScript" RUNAT=SERVER> sub viewSource(\$){ use LWP::Simple; my ($URL) = @_; $Source = get($URL); if($Source ne "") { return true; } else { return false; } } </script> </HEAD>
<BODY> <p><center> <font face="arial, helvetica" size="-2">URL Validator by Huw Reddick<br> </center><p>
<% if Request.querystring("url") <> "" then if viewSource(Request.querystring("url")) then response.write(Request.querystring("url")) else response.write("not found") end if End If %> </font> </body> </html>
Just save the code as http_asp.asp
|
 |
|
aspdesigner
Junior Member
 
165 Posts |
Posted - 01 July 2001 : 23:08:08
|
It looks like you may have a problem with the installation of ASPPerl on your server, Brad. I cut-and-pasted my code from this topic and uploaded it to a server (just to make sure I didn't make a typo), and it works perfectly! 
|
 |
|
aspdesigner
Junior Member
 
165 Posts |
Posted - 01 July 2001 : 23:55:36
|
The little form HTML in my program is certainly not critical, this was a test program designed to demonstrate how to do this, and the form was designed to make it easier for someone to use.
However, some of the code in my program is necessary in order for this program to function properly! I am sorry, HuwR, but your "simpler" version has a couple problems.
First, I discovered (at least with my server) that if you do not provide the proper internet protocol prefix (such as http://) in a URL that you pass to an LWP::Simple get or head library request, it can cause an error, resulting in your program incorrectly claiming that a web site is down when in fact it is not!
My program is designed to detect and correct this. 
Second, you are using a "get" request to check if a site is up. This results in the entire web page being transfered from their server to yours, just to check if the site is up! There is a much less wasteful means of accomplishing the same task.
My program uses a "head" call instead, which generates an HTTP HEAD request to the other server, and eliminates the need to transfer the entire web page just to see if the server is up.
For those of you who have ever looked at raw server logs, you have probably seen "HEAD" requests before. This is the same approach most search engines use to check if a site is still up or has changed, for the same reason - it is more efficent and does not waste bandwidth.
If you want to run the program by manually including the URL to test in the command line as suggested, you can do that with my program as well. Simply do this -
CheckURL.asp?PageURL=www.msn.com
This will execute the program, displaying the results and providing a form where you can enter another URL to check. If you really do not want the form, you can also simply remove the four lines containing it from the code to make a command-line only version. 
|
 |
|
Doug G
Support Moderator
    
USA
6493 Posts |
Posted - 02 July 2001 : 00:39:48
|
Deja-vu
====== Doug G ====== |
 |
|
|
Topic  |
|