#!/usr/bin/perl -w # Confuse Google with random searches # # Actually follow some of the links that it returns, so it thinks they were relevant. # # (c) Phil Carmody, 2014, distributed under the CC BY-SA 3.0 license # my $dict; my $wcount=2; my $follow=2; my ($sleepmin,$sleepmax)=(20,80); while(@ARGV and $ARGV[0]=~/^-(\w)/) { my $a=shift(@ARGV); if($a=~m/-d=(.*)/ and -r $1) { $dict=$1; } elsif($a=~m/-c=(\d+)/) { $wcount=int($1); } elsif($a=~m/-f=(\d+)/) { $follow=int($1); } elsif($a=~m/-s=(\d+)-?(\d*)/) { ($sleepmin,$sleepmax)=($1,$2//$1); } elsif($a=~m/-h/) { die("-d= -c= -f= -s=[-]\n"); } } $dict//=$ENV{'DICT'}//'/usr/share/dict/words'; sub getRandWords($$) { my @w = `shuf -n $_[0] '$_[1]'`; if(scalar(@w) != $_[0]) { die ("shuf -n $_[0] '$_[1]' yielded ".scalar(@w)." lines"); } map { chomp; my @tmp=split(/\s+/, $_); print("line was $_ -> [ @tmp ]\n"); $_=$tmp[int(rand(scalar(@tmp)))]; } @w; @w; } my @words=getRandWords($wcount,$dict); my $url = "http://www.google.com/search?q=".join("+",@words); my $tmp = "/tmp/googoo.$$.html"; system("w3m -dump_source '$url' > '$tmp'"); open(H, "<$tmp") or die("log file $tmp not created"); my @followable=(); while() { # print("GOT: $_"); while($_ =~ s@.*?href=['"]?(.*?)["' ]@@s) { my $link=$1; next if($link !~ m@/url\?q=@); ++$seen; if(scalar(@followable)<$follow) { push(@followable, $link); } elsif((my $insert=rand($seen))<$follow) { $followable[int($insert)] = $link; } } } close(H); unlink($tmp); foreach my $flink (@followable) { $flink=~s/&/&/g; # print("Following $flink\n"); my $sleep=$sleepmin+rand($sleepmax-$sleepmin); print("sleep $sleep; w3m -l 50 -dump -header 'Referer: $url' 'http://www.google.com$flink'\n"); sleep($sleep); system("w3m -l 50 -dump -header 'Referer: $url' 'http://www.google.com$flink'"); }