#!/usr/bin/perl use strict; use warnings; # History: # conray - 19.02.2010 : 19:31 UTC - initial version with ping (-ping) # betterworld - 19.02.2010 : 19:44 UTC - minor changes # esskar - 19.02.2010 : 20:27 UTC - changes on ping, and dump myself command (-dump) # topeg - 19.02.2010 : 00:02 UTC - addded mirror # Kalle - 01.03.2010 - added technology assimilation automation # conray - 02.02.2010 21:07 - added Helpfunktion (-help) and changes on Ping-Parameter # conray - 03.02.2010 19:28 - added Password-Generator (-pwgen) # conray - 08.03.2010 21:35 - added print location (-whereami) # steferbo - 08.03.2010 23:10 - added get country from ip (-get_country) # topeg - 09.03.2010 23:46 - changed to GetOpt::Long, adapt assimilate ping, pwgen and get_country, added dummy (--dummy), added truemirror (--truemirror ) # steferbo - 12.03.2010 22:30 - added steuern2010 use Getopt::Long; use FindBin; use Net::Ping; use LWP::UserAgent; use HTTP::Cookies; use File::Basename; #EierlegendeWollMilchSau.pl my %opts=(); my @runn=(); my %commands=( ######################################################################## ######################################################################## #_______________________________________________________________________ 'dummy' => [ "dummy\t\tDoing nothing!", sub { # empty. }], #_______________________________________________________________________ 'help|h' => [ "help\t\tprint out this usagetext", sub{ HELP(); }, 'runn now'], #_______________________________________________________________________ 'ping=s,range=i' => [ "ping [--range=]\t\ttrys to ping an ip or an range of ip addresses.", sub { #exmark-ping-start my ($ip,$till) = @_; my @r = split(/\./, $ip); $till=$r[3] unless(defined($till)); my $until = $till + 1; while ($r[3] < $until ) { $ip = join '.', @r; my $ping = Net::Ping->new('icmp', 1, 64 ); print "$ip " . ($ping->ping($ip) ? 'online' : 'offline') . "\n"; $r[3]++; } #exmark-ping-stop }], #_______________________________________________________________________ 'dump' => [ "dump\t\tdumps itself to STDOUT", sub { #exmark-dump-start my $path = "$FindBin::Bin/$FindBin::Script"; open(my $myself, "< $path") or die "Unable to open myself ($path): $!"; while(<$myself>) { print $_; } close $myself; #exmark-dump-stop }], #_______________________________________________________________________ 'devil' => [ "devil\t\tDon't try that", sub { #exmark-devil-start print "So long, and thanks for all the fish.\n"; unlink $0 or die "Will not stop :'-(\n"; #exmark-devil-stop }], #_______________________________________________________________________ 'mirror=s' => [ "mirror \t\tmirror file or STDIN", sub { #exmark-mirror-start my $fh=\*STDIN; my $file=shift; open($fh,'<',$file) || die("ERROR open $file ($!)") if($file && $file ne '-'); chomp($_) && print reverse($_)."\n" while(<$fh>); close($fh); #exmark-mirror-stop }], #_______________________________________________________________________ 'truemirror=s' => [ "truemirror \t\tmirror file or STDIN", sub { #exmark-truemirror-start my $fh=\*STDIN; my $file=shift; open($fh,'<',$file) || die("ERROR open $file ($!)") if($file && $file ne '-'); my @lines=(); my $length; while (my $line=<$fh>) { $length=length($line) if(!defined($length) || $length/)(][}{\/\\´`> [ "assimilate newparam.pl\t\tassimilate more perl code into this script", sub { #exmark-assimilate-start my $newtechsource=shift; my $borgtechnology; my $assimilationspace; my $newtechnology; my ($newcmdname)=split(/\./,$newtechsource,0); $newcmdname=~y/=|!?//d; $newcmdname=~s/\s+/_/s; my ($borgbase,$borgpath)=fileparse($0); my $newborgtechnology="${borgpath}Neue$borgbase"; if (open($borgtechnology,'<',$0)) { if (open($assimilationspace,'>',$newborgtechnology)) { if (open($newtechnology,'<',$newtechsource)) { while(<$borgtechnology>) { if (/^# <-- don't touch this/) { my $thisline=$_; print "Assimiliere neue Technologie...\n"; print $assimilationspace qq! #exmark-assimilate-stop #_______________________________________________________________________ '$newcmdname' => [ "$newcmdname\\t\\t assimilated weird stuff", sub { #exmark-assimilate-part-start !; while(<$newtechnology>) { next if (/^#!|^use strict;|^use warnings;/); print $assimilationspace $_; } close($newtechnology); print $assimilationspace qq! }, 'runn now'], $thisline!; } else { print $assimilationspace $_; } } close($borgtechnology); if (close($assimilationspace)) { print "Widerstand war zwecklos!\nNeue Technologie einsetzbar: Neue$borgbase --$newcmdname\n"; } else { print "Aktivierungssequenz ungültig. Assimilation abgebrochen.\n"; } } else { print "Neue Technologie kann nicht assimiliert werden. Abbruch der Assimilation\n"; } } else { print "Fluktuation im temporären Raum-/Zeitgefüge. Abbruch der Assimilation.\n"; } } else { print "Wo sind wir ? Es ist so....leise. Bring uns nach Hause!\n"; } #exmark-assimilate-part-stop }], #_______________________________________________________________________ 'pwgen=i' => [ "pwgen\t\tgenerates an (secure) password", sub { #exmark-pwgen-start my $input=shift; unless($input) { print "How much positions your password should have?\n"; print "Note: Secure passwords have 10 positions as minimum \n"; $input=; chomp $input; } $input=~s/[^\-\d].+$//; $input=abs($input); my @bletters = ("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"); my @sletters = ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"); my @numbers = ("1", "2", "3", "4", "5", "6", "7", "8", "9", "0"); my @special = ("!", "\.", "\$", "\%", "\&", "?", "\/", "\\", "\,", "-", "_", "\#", "\*", ":", "(", ")", "=", "+", "<", "§", "[", "]", "\;"); my $pw=''; while (length($pw) != $input) { my $n1 = int(rand(26)); my $n2 = int(rand(26)); my $n3 = int(rand(10)); my $n4 = int(rand(23)); my $z = int(rand(4)); if ($z == 0) { $pw = $pw . $bletters[$n1]; } elsif ($z == 1) { $pw = $pw . $sletters[$n2]; } elsif ($z == 2) { $pw = $pw . $numbers[$n3]; } elsif ($z == 3) { $pw = $pw . $special[$n4]; } else { print "There is bug"; exit; } } print "The generated Password is: $pw \n"; #exmark-pwgen-stop }], #_______________________________________________________________________ 'whereami' => [ "whereami\t\tprint out the filelocation", sub { #exmark-whereami-start print __FILE__."\n"; #exmark--whereami-stop }], #_______________________________________________________________________ 'get_country=s' => [ "get_country \t\tsingle-host 32bit decimal", sub { #exmark-get_country-start my $ip = shift; my $line=""; my $country=""; my $out="IP: $ip is non-registered"; my $whois="http://www.utrace.de/whois/"; my $hol=$whois.$ip; my $html=stuff($hol); $html =~ s/<([^>]|\n)*>//mig; $html =~ s/ //mig; (my @text)=split(/\n/,$html); foreach $line (@text){ if( $line =~ /country:/ig ){ $line =~ s/\s//ig; (my $nix, $country)=split(/:/,$line); $out="IP: $ip has country-code: $country"; goto ELMS; } # end if } # end foeach ELMS: print $out; #exmark-get_country-stop }], #_______________________________________________________________________ 'export=s, filename=i' => [ "export parameter [--file=]\t\texports a part of this script into a standalonescript", sub { my ($com, $file) = @_; my $line; open (out, ">> $file"); print out '#!/usr/bin/perl'; print out 'use strict;'; print out 'use warnings;'; print out 'use FindBin;'; print out 'use Net::Ping;'; print out 'use LWP::UserAgent;'; print out 'use HTTP::Cookies;'; print out 'use File::Basename;'; close out; if ($com == "assimilate" || $com == "get_country") { while($line = <__FILE__> ) { if ($line =~ /^\Q\#exmark-$com-start\E/ .. $line =~ /^\Q\#exmark-$com-start\E/) { open (out, ">> $file"); print out $line; close out; } if ($line =~ /^\Q\#exmark-$com-part-start\E/ .. $line =~ /^\Q\#exmark-$com-part-start\E/) { open (out, ">> $file"); print out $line; close out; } } } else { while($line = <__FILE__> ) { if ($line =~ /^\Q\#exmark-$com-start\E/ .. $line =~ /^\Q\#exmark-$com-start\E/) { open (out, ">> $file"); print out '#!/usr/bin/perl'; print out $line; close out; } } } }], #_______________________________________________________________________ 'steuer2010' => [ "steuer2010\t\tSteuer2010 - ESt und SolZ ", sub { #exmark-steuer2010-start print "\n\nzu versteuerndes Einkommen: "; chomp (my $x = ); my $est=0;my $soli=0;my $estsplit=0; my $solisplit=0; if($x > 8004 && $x < 13470){$est=int((912.17*($x -8004)/10000+1400)*($x- 8004)/10000);} if($x > 13469 && $x < 52882){$est=int((228.74*($x -13469)/10000+2397)*($x-13469)/10000+1038);} if($x > 52881 && $x < 250731){$est=int($x*0.42-8172);} if($x > 250730){$est=int($x*0.45-15694);} my $xx=$x/2; if($xx > 8004 && $xx < 13470){$estsplit=int((912.17*($xx -8004)/10000+1400)*($xx- 8004)/10000)*2;} if($xx > 13469 && $xx < 52882){$estsplit=int((228.74*($xx -13469)/10000+2397)*($xx-13469)/10000+1038)*2;} if($xx > 52881 && $xx < 250731){$estsplit=int($xx*0.42-8172)*2;} if($xx > 250730){$estsplit=int($xx*0.45-15694)*2;} if($est > 972){$soli=int($est*0.055);} if($estsplit >1944){ $solisplit=int($estsplit*0.055); my $test= int(($estsplit-1944)*0.2); if ($solisplit > $test){$solisplit=$test;} } my $netto=$x-$est-$soli; my $nettosplit=$x-$estsplit-$solisplit; print"\n \t - (ohne Kirche/Kind) Steuer 2010 - \n\n"; print" \tGrundtarif \t Splitting \n\n"; print" ESt: \t$est \t $estsplit \n\n"; print" (* Vorbehalt) SolZ: \t$soli \t $solisplit \n\n"; print" ----------------------------------------- \n"; print" Netto: \t$netto \t $nettosplit \n"; print"\n\n * if(Verfassungsgericht_Urteil eq \"widerrechtlich\") {automatische Erstattung}\n\n"; #exmark-steuer2010-stop }, 'runn now'], # <-- don't touch this ######################################################################## ######################################################################## ); for(keys(%commands)) { my $opt=$_; my $cmdref=$commands{$_}[1]; my $runn_mod='runn last'; $runn_mod=lc($commands{$_}[2]) if(exists($commands{$_}[2])); my @olist=split(/\s*,\s*/s,$opt); if($runn_mod eq 'runn now') { for(@olist) { $opts{$_}=sub{ $cmdref->(pop(@_)); } } } elsif($runn_mod eq 'runn first') { for my $pos (0..$#olist) { die("no option in $opt position $pos\n") unless($olist[$pos]); $opts{$olist[$pos]}=sub{ add_cmd($opt,pop(@_),$pos,1); } } } elsif($runn_mod eq 'runn last') { for my $pos (0..$#olist) { die("no option in $opt position $pos\n") unless($olist[$pos]); $opts{$olist[$pos]}=sub{ add_cmd($opt,pop(@_),$pos,0); } } } else { die(qq#Can't interpret runn modifier "$runn_mod" \n#); } } my $ok=GetOptions(%opts); HELP(@ARGV) if(@ARGV); HELP(0) unless($ok); for my $cmd (@runn) { my $name=shift(@$cmd); $commands{$name}->[1]->(@$cmd); } ######################################################################## # FUNCTIONS ############################################################ ######################################################################## sub stuff { #exmark-get_country-part-start my $url=shift; my $agent="Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.18) EierlegendeMilchSau/1.0.0"; my $cookie = HTTP::Cookies->new; my $req = HTTP::Request->new(GET => $url); $req->header('Referer', ''); $req->header('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'); $req->header('Accept-Language', 'de-de,de;q=0.8,en-us;q=0.5,en;q=0.3'); $req->header('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.7'); $req->header('Keep-Alive', '115'); $req->header('Cache-Control', 'max-age=0'); my $browser = LWP::UserAgent->new; $browser -> agent($agent); $browser -> cookie_jar($cookie); my $res = $browser->request($req); my $stuff = $res->content; return ($stuff); #exmark-get_country-part-stop }# end sub stuff sub add_cmd { my $name=shift; my $opt=shift; my $pos=shift || 0; my $first=shift || 0; for my $ref (@runn) { if($ref->[0] eq $name) { $ref->[$pos+1]=$opt; return; } } if($first) { unshift(@runn,[$name,$opt]); } else { push(@runn,[$name,$opt]); } } sub HELP{ my @errors=@_; my @list=(); my $length_first; my $length_second; for my $cmd (sort keys(%commands)) { $length_first=length($cmd) if(!defined($length_first) || $length_first[0],2); $desctxt='' unless($desctxt); $cmdtxt='' unless($cmdtxt); $length_second=length($cmdtxt) if(!defined($length_second) || $length_second\n\n"; print $oh "parameters:\n"; for(@list) { printf $oh " %-${length_first}s => --%-${length_second}s %s\n", @$_; } print $oh "\n"; exit(@errors?1:0); } __END__