#!/usr/bin/perl
# mikes down and dirty cut and paste perl code emporium. 
# This works for me.. When I have an Adword I want to rise to the top. Run
# from multiple IP's. (servers, clients..)

# Note this code is an example.. and use may or will incur monetary charges
# and/or damages which you will be responsible for. 

use LWP::UserAgent ; 
use HTTP::Request;
use HTTP::Response;
use URI::Heuristic;

$loop = 0 ;  # Gotta start somewhere
$max = 200 ; # times to loop
$inc = 10 ;  # hit increment
$start = 0 ; # Again, gotta start somewhere

while($loop < $max) { 

#This example searches for web hosting companies.
# and raises the link for 'BubbalandTech.Com' for example.

$targetstring = "BubbalandTech.com" ; 
$host = "www.google.com/search?q=web+hosting&hl=en&start=$start&sa=N" ; 
# This should be all you have to edit... (see above 2 lines)
# The 'host' includes the words you want to 'stomp' and raise the ranking for


&getit ; 
&parseit ; 
$loop++ ; 
$start = $start + $inc ; 
sleep 20 ; 
print "LOOP: $loop   $host\n" ; 

} ;
 

sub getit {
		unlink("/tmp/google") ; 
		$url = URI::Heuristic::uf_urlstr($host) ; 
		#print "HTTP $url \n" ;
		my $ua = LWP::UserAgent->new() ; 
		$ua->agent("Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461; Cox High Speed)") ; 
		#print "looking for $url \n" ; 
		my $req = HTTP::Request->new(GET => $url) ; 
		$req->referer("http://geeklabs.com") ; 
		my $response = $ua->request($req) ; 
		if ($response->is_error()) {
			print "ERROR $host" ; 
			$s = $response->status_line ; 
			$s =~ s/\'//g ; 
			print "FAILED: $s\n" ; 
		} else {
			my $count ; 
			my $bytes ; 
			my $content = $response->content() ; 
			$bytes = length $content ; 
			#$count = ($content =~ tr/\\n/\n/) ; 
			$content =~ s/\/tmp/google") ; 
			print OUT "$content" ; 
			close OUT ; 
			print "$url is OK $bytes bytes\n" ; 

		} ; 

} ; 	


sub parseit { 
if(-e "/tmp/google") { 
open(TMP,"/tmp/google") ; 
print "\n" ; 
	while() { 
		print "." ; 

		if(/$targetstring/) { 
			print "\n\nFOUND\n\n" ; 
			
			# if ($_ =~ /(.*)\a href\=(.*) on(.*)/) { print "\n$2\n" ; } ; 
			if ($_ =~ /(.*)a href=(.*)\ onMouseOver(.*)/) { 
	
				$link = $2 ; 
				print "\n$link\n" ; 

				open(G,">>/tmp/list") ; 
				print G "$link\n" ; 
				close G ; 

				sleep 20 ; &stomp ; sleep 30 ; $start = 0 ; 

			} ; 

			# print "\n$_\n" ; 
			

		} ; 
	} ; 
} ; 
print "\n" ; 
} ; 

sub stomp {
		print "STOMPING $link\n" ; 
		$host = "www.google.com$link" ; 
		&getit ; 

} ;