Web browser providing visibility
Brick Robbins
brick at fastpack.com
Tue Dec 5 01:40:11 CST 2000
~sdpm~
Here is a quick, inelegant hack I put together a while back to see the http
headers and save various files the command line.
works for HTML, and other binaries. It was written for a WIN box, but
should work for most.
Any suggestions appreciated.
=========begin==============
#!/usr/local/bin/perl
# server.pl
$save_path = "c:\\windows\\desktop\\";
use Socket;
$|=1;
if (!defined ($ARGV[0])){
print "you must specify a server.\n\n
Proper use: perl server.pl www.domain.com/[url] [action] [file]\n
where action is the http method, usually GET, HEAD, POST (HEAD is
default)\n
and file specifies a filename in $save_path (optional)
where the stuff from the server gets saved\n";
exit;
}
if ($ARGV[2]){
print "opening file $save_path$ARGV[2] for writing\n";
open (SAVE, ">$save_path$ARGV[2]") || die "unable to save file $ARGV[2]:
$!\n";
binmode SAVE;
}
$ARGV[0] =~ s/^http:\/\///i;
($remote_server,$URL) = split (/\//,$ARGV[0],2);
($remote_server,$port) = split (/:/,$remote_server,2);
$port="80" unless $port;
if ($ARGV[1]){
$action = uc ($ARGV[1]);
}else {
$action = "HEAD";
}
##########################
if (!defined ($URL)){
$URL = "/";
}else {
$URL = "/$URL";
}
#
# open the TCP socket
#
print "connecting to:$remote_server port $port\n";
open_TCP("FILE","$remote_server",$port) || die("open_TCP failed");
binmode FILE;
#
# make the POST header
#
$headHeader="$action $URL HTTP/1.1
User-Agent: Mozilla/4.01 [en] (Win95; I)
Host: $remote_server
Accept: */*, image/gif, image/x-xbitmap, image/jpeg
";
print FILE "$headHeader"; #send the post header to the server
print "Sending reqest for $URL to $remote_server
==
$headHeader
==
Here is the response:
==
";
$i=0;
while (<FILE>){
$a[$i++]=$_;
($_ =~ m@</hmtl>@i ) && close(FILE);
if (($action =~ /HEAD/i) && ($_ =~ /^\s$/)){
close (FILE);
}
} #get the html doc back from the server
close (FILE);
print @a;
if ($ARGV[2]){
print SAVE "@a";
close SAVE || print "error closing SAVE";
}
print "\n===done===\n";
exit;
#########################################
#
# opens a TCP socket to the server specified
#
# $FS - file handle
# $dest - server URL
# $port - server port, defaults to 80
#
###########################################
sub open_TCP{
my ($FS, $dest, $port) = @_;
$port || ($port = 80); #default port to 80
my(@proto) = getprotobyname('tcp');
socket($FS, PF_INET, SOCK_STREAM, $proto[2]) || die("died in first
socket call:$!");
my $sin = sockaddr_in ($port,inet_aton($dest));
connect ($FS,$sin) || die("died in connect: $!");
my ($old_fh) = select ($FS);
select ($old_fh);
return (1);
}
~sdpm~
The posting address is: san-diego-pm-list at hfb.pm.org
List requests should be sent to: majordomo at hfb.pm.org
If you ever want to remove yourself from this mailing list,
you can send mail to <majordomo at happyfunball.pm.org> with the following
command in the body of your email message:
unsubscribe san-diego-pm-list
If you ever need to get in contact with the owner of the list,
(if you have trouble unsubscribing, or have questions about the
list itself) send email to <owner-san-diego-pm-list at happyfunball.pm.org> .
This is the general rule for most mailing lists when you need
to contact a human.
More information about the San-Diego-pm
mailing list