#! /usr/bin/perl use IO::Socket::SSL; use Socket; # For constants like AF_INET and SOCK_STREAM use IO::Select; $proto = getprotobyname('tcp'); #get the tcp protocol # 1. create a socket handle (descriptor) my($sock); socket($sock, AF_INET, SOCK_STREAM, $proto) or die $!; # 2. connect to remote server $remote = '23.56.135.7'; $port = 443; $iaddr = inet_aton($remote) or die "Unable to resolve hostname : $remo +te"; $paddr = sockaddr_in($port, $iaddr); #socket address structure connect($sock , $paddr) or die "connect failed : $!"; print "Connected to $remote on port $port\n"; #$answer = <$sock>; #while(<$sock>){ sysread ($sock); print $answer;} my $buf = ''; my $header; for (;;) { my $rv = sysread($sock, $buf, BLK_SIZE, length($buf)); die("Can't read: $!\n") if !defined($rv); die("Can't read: Premature EOF\n") if !$rv; if ($buf =~ s/^(.*\r\n\r\n)//s) { $header = $1; last; } }
[download]