#!/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)
use FindBin;
use Net::Ping;
#EierlegendeWollMilchSau.pl
my $cmd = lc shift @ARGV;
if ($cmd eq '-ping' ) #ping
{
my $ip = shift @ARGV
or die "No ip.";
my @r = split(/\./, $ip);
my $till = shift(@ARGV) || $r[3];
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]++;
}
}
elsif($cmd eq '-dump')
{
my $path = "$FindBin::Bin/$FindBin::Script";
open(my $myself, "< $path") or die "Unable to open myself ($path): $!";
while(<$myself>) { print $_; }
close $myself;
}
elsif( $cmd eq '-devil' )
{
print "So long, and thanks for all the fish.\n";
unlink $0 or die "Will not stop :'-(\n";
}
elsif($cmd eq '-mirror')
{
my $fh=\*STDIN;
my $file=shift;
open($fh,'<',$file) || die("ERROR open $file ($!)") if($file);
chomp($_) && print reverse($_)."\n" while(<$fh>);
close($fh);
}
elsif($cmd eq '-assimilate')
{
my $newtechsource=shift @ARGV;
my $borgtechnology;
my $assimilationspace;
my $newtechnology;
my ($newcmdname)=split(/\./,$newtechsource,0);
use File::Basename;
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 (/\\t-assimilate newparam.pl\\t/) {
print $assimilationspace $_;
print $assimilationspace " print \"\\t-$newcmdname\\t\\t assimilated weird stuff\\n\";\n";
}
elsif (/^# elsif\(MORE\) \{ \}/) {
my $thisline=$_;
print "Assimiliere neue Technologie...\n";
print $assimilationspace "elsif(\$cmd eq \'-$newcmdname\')\n\{\n";
while(<$newtechnology>) {
next if (/^#!|^use strict;|^use warnings;/);
print $assimilationspace $_;
}
close($newtechnology);
print $assimilationspace "\}\n$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";
}
}
elsif ($cmd eq '-pwgen')
{
print "How much positions your password should have?\n";
print "Note: Secure passwords have 10 positions as minimum \n";
my $input=<STDIN>;
chomp $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 = ("!", "\.", "\$", "\%", "\&", "?", "\/", "\\", "\,", "-", "_", "\#", "\*", ":", "(", ")", "=", "+", "<", "§", "[", "]", "\;");
our $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";
}
elsif($cmd eq '-help')
{
print "usage: EierlegendeWollMilchSau.pl <parameters>\n\n";
print "parameters:\n";
print "\t-ping <ip> [range]\t\ttrys to ping an ip or an range of ip addresses.\n";
print "\t-dump\t\t\tdumps itself to STDOUT\n";
print "\t-devil\t\t\tDon't try that\n";
print "\t-mirror [file]\t\t mirror file or STDIN\n";
print "\t-assimilate newparam.pl\t assimilate more perl code into this script\n"; #<-- don't touch this
print "\t-get_country\t\t assimilated weird stuff\n";
print "\t-pwgen generates an (secure) password\n";
print "\t-get_country <ip> \t single-host 32bit decimal\n";
print "\n";
}
elsif ($cmd eq '-whereami') {
print __FILE__;
}
elsif($cmd eq '-get_country')
{
my $ip = shift @ARGV;
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;
sub stuff {
use LWP::UserAgent;
use HTTP::Cookies;
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);
}# end sub stuff
}
# elsif(MORE) { } <-- don't touch this
else
{
print "Type ./EierlegendeMilchSau.pl -help for more informations \n";
exit 0;
}
__END__