Jerry Wayne Odom Jr.


#!/usr/bin/perl
use Socket;
sub open_TCP;


# contact the server on a given port. In this case 80
while (open_TCP(F, "www.google.com", 80) == undef) {
#loop because sometimes they don't respond the first time
print "Error connecting to server at www.google.com\n";
sleep(1); #just so it doesn't get too carried away
}

#make the request using all the appropriate headers.
#In this case we're hiding our agent by pretend we're a web browser
#each line of a header is ended with a newline and the request is ended with 2 newlines

print F "GET / HTTP/1.1\n" .
"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, " .
"application/vnd.ms-powerpoint, application/msword, */*\n" .
"Referer: http://www.google.com\n" .
"Accept-Language: en-us\n" .
"Content-Type: application/x-www-form-urlencoded\n" .
"Accept-Encoding: gzip, deflate\n" .
"User-Agent: Mozilla/4.0\n" .
"Host: www.google.com\nContent-Length: 98\n" .
"Connection: Keep-Alive\n" .
"Cache-Control: no-cache\n\n";
#note that a request is ended by 2 newlines. 1 newline and it'll just hang

while($return_line = ) #while we still have data returned from the server in the file handle
{
print $return_line;
}
close(F); #close the connection
exit; #get out


sub open_TCP
{
# get parameters
my ($FS, $dest, $port) = @_;
my $proto = getprotobyname('tcp');
socket($FS, PF_INET, SOCK_STREAM, $proto);
my $sin = sockaddr_in($port,inet_aton($dest));
connect($FS,$sin) || return undef;
my $old_fh = select($FS);
$| = 1; # don't buffer output
select($old_fh);
1;
}

 

© 2002, Jerry Odom