[thelist] Can you open a url with a cgi script?

Dean Mah webmaster at server.bmod.athabascau.ca
Thu Aug 7 22:49:54 CDT 2003


On Thu, Aug 07, 2003 at 06:30:29AM -0700, Diane Soini wrote:

> I can't use PHP nor can I recompile or change the server or install
> anything like modules or anything other than cgi scripts into the
> cgi-bin and html pages into the site files. I'm hoping there is perl
> code I could use to open a file on another server, read its contents
> and print out to the browser without redirecting to that other
> server.  Is there anything like that out there?


You'll have to tweak it a little but try the following:


#!/usr/bin/perl -w

use strict;
use Socket;

my $ip = inet_aton($ARGV[0]) || die "inet_aton: $!\n";

socket(HTTP, PF_INET, SOCK_STREAM, getprotobyname('tcp')) || die "socket: $!\n";
connect(HTTP, sockaddr_in(80, $ip)) || die "connect: $!\n";

my $old_fh = select(HTTP);
$| = 1;
select($old_fh);

print HTTP "GET / HTTP/1.0\n\n";

while (defined(my $line = <HTTP>)) {
    print $line;
}

close(HTTP) || die "close: $!\n";

1;


Dean


More information about the thelist mailing list