As a technical support engineer, I would need to send multiple spam samples through our product for detection rate. I initially used a bash script to send the samples through via telnet command. The drawback was that the processing was sequential (slow). I was already thinking of how to use threading to send the samples through in large batches which finishes the job a lot faster and at the same time enables me to tune the performance of our product when handling multiple connections. Finally, after a great deal of procastrination, I finally hacked together a perl script to do the job, after googling and modifying some ther perl scripts. I used the script from http://pentestit.com/2009/05/20/source-code-perl-multithreaded-scanner-webdavenabled-servers/ as basis for my script.
#!/usr/bin/perl -w
$|++;
use strict;
use 5.008;
use threads;
use threads::shared;
use Thread::Queue;
use Net::SMTP;
our $thrnum:shared=100;
our $q:shared;
our @threads;
sub smtp_send {
my $target='192.168.50.135';
my $filename;
my $line;
my @message;
my $dir = shift;
if ($dir =~ m/\/$/) { } else { $dir = $dir."/";};
$filename = shift;
# print "Opening connection to target : ".$target."\n";
# print "Filename: ".$dir.$filename."\n";
$filename=$dir.$filename;
open FILE, $filename or die $!;
@message=
close FILE;
if (my $smtp = Net::SMTP->new($target,Hello=>'peters.eatsc.ts',Timeout=>30,Debug=>0)) {;
$smtp->mail('test@test.bng');
$smtp->to('peters@eatsc.ts');
$smtp->data(@message);
$smtp->quit;
} else {
die;
};
}
sub main {
my $dir;
my $spamfile;
my $running;
$q = new Thread::Queue;
$dir = shift;
opendir (DH, $dir);
while (defined ($spamfile=readdir(DH))) {
unless ($spamfile =~ /^.{1,2}$/) {
$q->enqueue($spamfile);
}
}
closedir(DH);
while (1){
@threads = threads->list;
if ($q->pending > 0) {
# print "Pending items: ".$q->pending." \n";
if ($#threads <= $thrnum+1) {
threads->new(\&spam_send,$dir,$q->dequeue);
# print "Adding new thread ".$#threads." \n";
} else {
foreach $running(@threads) {
$running->join;
# print "Freeing thread: ".$#threads." \n";
};
};
} else {
if ($#threads >= 0) {
foreach $running(@threads) {
$running->join;
# print "Freeing thread: ".$#threads." \n";
};
exit;
};
};
# print "\nThread count:" .$#threads;
}
&main($ARGV[0]); #input directory name as command-line parameter.
I will be recoding this script in python and ruby to check which one will run faster (not that I expect that there will be a huge change in performance, but a programming exercise for me).
Just these past few days, the Big Three raised pump prices by 2 pesos at most. The government, legislators and militant groups immediately raised their ferocious objections against this insensitive move. The Palace even passed an Executive Order mandating the immediate rollback of the price increase. This, IMHO, is just a short term solution to beef up the sagging reputation of the current administrator, and at the same time, serves as a trumpet call by those politicians hankering for public limelight.
Oil price increase is inevitable. Oil is a decreasing commodity. In time, market forces will demand the price increase. What our politicos should do is explore renewable sources of energy and ways to lessen our consumption of petroleum products. This is a far more effective way of combating the incessant oil price increase. But I doubt if they will ever seriously consider taking these needed steps, since they are known more for blowing hot air than doing things.
Streamline the public transport system. We have too many buses and jeepneys, which are not even fuel-efficient. Worse yet, they are among the top contributors of air pollution. Water and rail transport are feasible alternatives only if our national and local government officials would stop pandering to other stuff for their own advantage.
Tidal generators to generate electricity. We are an archipelago, for crying out loud. Too costly, they say? Stop corruption, then we will have enough money to implement these.
incentive program, n.: The system of long and short-term rewards that a corporation uses to motivate its people. Still, despite all the experimentation with profit sharing, stock options, and the like, the most effective incentive program to date seems to be "Do a good job and you get to keep it."