#!/usr/local/bin/perl ######################################################### # wwwpost - A WWW http poster. # # # # POST saved raw form data to a url (cgi script). # # URL to post to and datafile taken from command line. # # # # Usage: wwwpost http://domain.com/form.cgi datafile # # # # Datafile should contain one set of raw (url-encoded) # # form data on each line (blank lines ignored). # # # ######################################################### # Written by David Efflandt (efflandt@xnet.com) 7/13/97 # # Based on wwwgrab # # Written by Jeff Ballard (ballard@cae.wisc.edu) 7/2/95 # # URL: http://www.engr.wisc.edu/~ballard/ # ######################################################### # This program is freeware. *NO* warranty is expressed,# # implied, nor granted to you in any way. Use of this # # program is at your own risk. # ######################################################### # Log POST reply to this file (uncomment to log results). # $postlog = 'post.log'; # Required for perl5. use Socket; # Given an http address, rip it into its coresponding parts. ($_, $datafile) = @ARGV; if (!$_) { print "Usage: $0 http://www.any.site/form.cgi datafile\n"; print " Where datafile is raw (url-encoded) form data to post,\n"; die " one complete form per line (blank lines ignored).\n"; } /http:\/\/([^\/]*)\/*([^ ]*)/; $site = $1; $file = "/$2"; if (!$site) { die "Incorrect URL in command line\n"; } $_ = $site; /^([^:]*):*([^ ]*)/; $site = $1; $port = $2; $port = 80 unless $port; $hostname = $site; #print STDERR "[$site] [$port] [$file]\n"; print "$datafile is empty or does not exist\n" unless (-s $datafile); open (IN, "<$datafile") || die "Can't open $datafile: $!\n"; while () { chop; $form = $_; $len = (length $form); &post_form if $form; sleep(2); # optional } # Open a socket and post the data sub post_form { ($sockaddr,$there,$response,$tries) = ("Snc4x8"); $there = pack($sockaddr,2,$port, &getaddress($hostname)); ($a, $b, $c, $d) = unpack('C4', $hostaddr); $proto = (getprotobyname ('tcp'))[2]; if (!socket(S,AF_INET,SOCK_STREAM,$proto)) { die "Socket Error: $!\n";} if (!connect(S,$there)) { die "Can't connect: $!\n"; } select(S);$|=1; select(STDOUT); print S "POST $file HTTP/1.0\n"; print S 'Host: ' . "$hostname\n" print S "Content-Type: application/x-www-form-urlencoded\n"; print S "Content-Length: $len\n\n"; print S "$form"; if ($postlog) { open(OUT,">>$postlog") || warn "Can't open $postlog: $!\n"; } while($line = ) { print OUT $line if ($postlog); print $line; } close(S); print "\n"; if ($postlog) { print OUT "\n"; close(OUT); } } sub getaddress { local($host) = @_; local(@ary); @ary = gethostbyname($host); return(unpack("C4",$ary[4])); }