use Socket;
die "Usage: httphead.pl <urls>" unless (@ARGV);
for $url (@ARGV)
{
print("$url doesn't look like an http URL\n"), next unless $url =~ m{^http://([^/:]+)(?:\:(\d+))?(/.*)}i;
$host = $1;
$port = 80;
$port = $2 if $2;
$uri = $3;
socket S, PF_INET, SOCK_STREAM, getprotobyname('tcp') or die "socket: $!";
$iaddr = inet_aton $host or die "no host: $host";
$paddr = sockaddr_in($port, $iaddr);
connect S, $paddr or die "connect: $!";
select S; $|=1; select STDOUT;
print S "HEAD $uri HTTP/1.1\015\012Host: $host\015\012\015\012";
while (<S>)
{
print;
last if /^\s*$/;
}
close (S) or die "close: $!";
}