#!/usr/bin/perl
#
# CONFIGURATION:
# Enter the IP address of the remote server
$host = "207.208.158.15" ;
# That's it. All configured!
# Call the script with the following:
######################################################################
use IO::Socket;
# We need one argument
unless (@ARGV == 1) { die "usage: $0 document" }
$document = shift ; # Document is the first command-line argument
$EOL = "\015\012"; # Formal net language. It's a multi-platform thing
$BLANK = $EOL x 2 ;
# Establish a tcp connection to $host's port 80
$remote = IO::Socket::INET->new( Proto => "tcp",
PeerAddr => $host,
PeerPort => "http(80)",
);
# Make sure we're talking to the host, not the Ether
unless ($remote) { die "cannot connect to http daemon on $host" }
$remote->autoflush(1); # I'm not sure what this does...
print $remote "GET $document HTTP/1.0" . $BLANK ; # Request the document
# Check for an appropriate response code
# The response code will be of the format:
#
# HTTP/1.x XXX blahblah
#
# We're interested in the XXX. This is the HTTP result code:
# 200 OK
# 302 Not changed since the last time you looked at it
# 403 Permission denied
# 404 Not found
$status = substr(<$remote>,9,3);
unless ( $status eq "200") {print "";exit(1)} ;
# Skip the rest of the response header
while ( length( <$remote> ) > 2 ) {}
# Now we're to the main content
while ( $line = <$remote> ) { # While there are lines left
print $line ; # Pass along the rest
}
close $remote; # Be nice; tell the server you're done
################################################################