All pastes #857022 Raw Copy code Copy link Edit

httphead.pl

public text v1 · immutable
#857022 ·published 2008-01-16 07:52 UTC
rendered paste body
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: $!";
}