Re: Simple WebServer Scanner (New perler, why downvotes?)
by ybiC (Prior) on Sep 21, 2001 at 21:19 UTC
|
It's sad to see young Asmo's reasonable effort at coding being downvoted. Of course the Other Ways To Do It in this thread are beneficial, and doubtless better, but the downvotes aren't a terribly monkish way to encourage new Perlers to learn and grow.
a bit less cheerful,
Don
striving toward Perl Adept
(it's pronounced "why-bick") | [reply] |
|
I agree completely. Have mercy o great monks!!!
%^+^%
| [reply] |
Re: Simple WebServer Scanner
by merlyn (Sage) on Sep 21, 2001 at 19:09 UTC
|
Your perl4-style code ignores the advances made in Perl in the past 8 years. Socket code without "use IO::Socket", and HTTP code without touching the LWP library. Feh!
use LWP;
use HTTP::Request::Common;
my $response = LWP::UserAgent->new->
simple_request(HEAD "http://perltraining.stonehenge.com");
unless ($response->is_error) {
print "server: ", $response->server, "\n";
} else {
print "error: ", $response->status_line, "\n";
}
-- Randal L. Schwartz, Perl hacker | [reply] [d/l] |
|
You're right about LWP of course and your version is
much nicer, but the original script does "use
Socket".
--
<http://www.dave.org.uk>
"The first rule of Perl club is you don't talk about
Perl club."
| [reply] |
|
| [reply] |
|
I am not advocating writing perl4 code but not all programmers have the right of installing new modules
on a given site. I don't know for this particular monk though.
-- stefp
| [reply] |
|
I already covered this in "No excuses about not using CGI.pm".
And hosting solutions are a dime-a-dozen these days. Not having basic tools
like IO::Socket (which is part of the core distribution) or LWP
available to you means you are burning a lot of time needlessly. Move to a different
server.
-- Randal L. Schwartz, Perl hacker
| [reply] |
A reply falls below the community's threshold of quality. You may see it by logging in. |
(jeffa) Re: Simple WebServer Scanner
by jeffa (Bishop) on Sep 21, 2001 at 19:42 UTC
|
Hmmmm . . . let's get the with times, eh? ;)
use strict;
use warnings;
use LWP;
my $url = shift || 'localhost';
$url = "http://$url";
my $agent = LWP::UserAgent->new();
my $request = HTTP::Request->new(HEAD => $url);
my $response = $agent->request($request);
print $response->{_headers}->{server}, "\n";
jeffa | [reply] [d/l] |
Re: Simple WebServer Scanner
by echo (Pilgrim) on Sep 21, 2001 at 19:32 UTC
|
Writing perl code is always nice, but in this case it seems overkill:
% perl -MCPAN -e 'install LWP'
% HEAD http://www.example.com/ | grep ^Server
| [reply] [d/l] |
|
perl -MCPAN -e 'install LWP'
Can't locate object method "install" via package "LWP" at -e line 1.
| [reply] [d/l] |
|
To work around this problem use:
perl -MCPAN -e shell
then at the prompt enter:
install LWP
Linuxboy
| [reply] |