Friday, May 25, 2007

PERL spammer

This will take a list of email addresses and a text file as input and smtp mail through your ISP. Fix the variable names and the addresses and run it! You may need to install SMTP-auth.pm

#!/usr/bin/perl

use Net::SMTP;

open(MESSAGE,"message.txt");
@message = ;

$SERVER="mail.isp.net";
$from="your@return.address";
$subject="Hi, everybody!";
$USERNAME="SMTP login name";
$PASSWORD="password";

open(ADDRESSES,"address_list.txt");

$smtp = Net::SMTP->new($SERVER,
#set to 1 for debugging Debug=>0,
) or die;

$smtp->auth($USERNAME, $PASSWORD) or die;

while () {
print "Now mailing to: $_";

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my @mons = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
my @wdays= qw( Sun Mon Tue Wed Thu Fri Sat Sun );
$year = $year + 1900;
$date= "$wdays[$wday], $mday $mons[4] $year $hour:$min:$sec -0400 (EDT)";

$head = "MIME-Version: 1.0\n"
. "From: $from\n"
. "To: $_ \n"
. "Date: $date\n"
. "Subject: $subject\n\n";

$smtp->mail("");
$smtp->to($_);
$smtp->data;
$smtp->datasend($head);

foreach $line (@message) { $smtp->datasend($line); }

$smtp->dataend;
}

$smtp->quit;

email address scraper

Cool little one-liner to get all the email addresses out of a text file. This is great for scraping HTML pages and creating mailing lists.


perl -wne'while(/[\w\.]+@[\w\.]+\w+/g){print "$&\n"}' test.txt

Wednesday, April 4, 2007

How to Win the Mega Millions Lottery

I wrote a PERL program that reads a simple text file of all the past winning numbers. You can copy and paste the numbers off the State Lotto Website. Make a text file called numbers.txt with the following format:

02/20/2007 01 09 26 46 51 11
02/13/2007 03 09 24 29 41 41
01/23/2007 03 05 15 26 53 35
01/19/2007 04 28 30 31 35 17
01/16/2007 04 08 15 33 52 10
01/05/2007 02 12 44 46 51 06
12/29/2006 03 04 10 39 50 29

While you're creating your history file, it's OK if you don't get the dates in order or if there's a lot of duplicates, the program will cull them out! Now run the PERL script. You will get a list of the most common winning numbers.

This works on the logic that if they've won before; they'll win again! If you like, you can play the least commonly drawn numbers as they are probably "due" to be drawn.

#!/usr/bin/perl
#read list of winners
open FILE, "numbers.txt" or die "Couldn't open winners";

#push unique drawing dates into array
while () {
$_ =~ s/\D/ /g;
($month, $day, $year, $a, $b, $c, $d, $e, $power) = split;
$drawing = $year . $month . $day . " " . $a ." ".$b." ".$c." ".$d." ".$e." ".$power."\n";
push (@uniq, $drawing) unless $seen{$drawing}++;
}

#count how freq each power ball number is drawn
foreach $drawing (@uniq) {
($date, $a, $b, $c, $d, $e, $power) = split / / , $drawing;
$ball{$a}++;
$ball{$b}++;
$ball{$c}++;
$ball{$d}++;
$ball{$e}++;
$pb{$power}++;
}

#Sort by most common winners
foreach $value (sort {$ball{$a} <=> $ball{$b} } keys %ball)
{
print "$value $ball{$value}\n";
}

#Sort and find the most winningest Power Ball
foreach $value (sort {$pb{$a} <=> $pb{$b} } keys %pb)
{
print "$value $pb{$value}\n";
}

That's it! There's some hooks that aneed development if you like. The $date is parsed out so you can use it to see when a number was last drawn. Also, the powerballs don't print out too neatly.

Comments are welcome. Good luck!

Sunday, February 25, 2007

Remove the common elements of two sets

I use this to see who from the first list has replied to my email. The script gives me a list of people to remail:


open(FILE, "addresses.txt") or die("Unable to open file");
@list = ;
close(FILE);

open(FILE, "replies.txt") or die("Unable to open file");
@stoplist = ;
close(FILE);


%temp = ();
@temp{@list} = ();
foreach (@stoplist) {
delete $temp{$_};
}
@list = sort keys %temp;


open(FILE, ">noreplies.txt") or die("Unable to open file");
print FILE @list;
close(FILE);