#!/bin/perl
use Socket;
$port = 8015;
($hostname, $path) = @ARGV;
if(! $path){
print "ERROR: usage: wget.pl hostname path\n"; exit(1);
}
if(! ($iaddr = inet_aton($hostname))){
print "ERROR: $iaddr host $hostname does not exist.\n"; exit(1);
}
$sock_addr = pack_sockaddr_in($port, $iaddr);
if(socket(SOCKET, PF_INET, SOCK_STREAM, 0) == 0){
print "ERROR: cannot create socket.\n"; exit(1);
}
if(connect(SOCKET, $sock_addr) == 0){
print "ERROR: cannot connect to host.\n"; exit(1);
}
select(SOCKET); $|=1; select(STDOUT);
print SOCKET "GET $path HTTP/1.0\r\n\r\n";
while (<SOCKET>){ m/^\r\n$/ and last; }
while (<SOCKET>){ print $_; }
# end.
|