Archive for the 'perl' Category

Tiny perl script for UDP flooding

Welcome to Linux Screw! If you're new here, you may want to subscribe our RSS feed.

Sometimes it is necessary to perform UDP flood towards some network device(s) in order to test its behavior in stress… Actually I am sure that every system administrator might use this small perl script for this purpose. Certainly there are many special programs for this but believe me that it is much more easier to do the following:

1. #touch > /tmp/flood.pl
2. #chmod +x /tmp/flood.pl
3. Copy the this code to /tmp/flood.pl:

4. Then /tmp/flood.pl 192.168.0.1 0 0 0, where 192.168.0.1 is IP you would like to flood with huge amount of UDP datagrams.

Thanks to Ivan Pepelnjak from http://ioshints.blogspot.com/.

Share This

Create Linux user with password

linux-logo.jpgSometimes it’s necessary to create Linux user accounts in batch mode (fully automatic) but often newbies ask how to set password for a new user without entering it manually. Thanks to heaven command useradd can get password as an input parameter, but it should be encrypted.

In other words, to create Linux user account with password the following command will be useful:

useradd -m -p encryptedPass username

I know at least two ways to get password encrypted. The first one is to use perl crypt(); function:

perl -e 'print crypt("password_to_be_encrypted", "salt"),"\n"'

which will give you an output sa3tHJ3/KuYvI.

The second way (more simple) is to use command:

openssl passwd password_to_be_encrypted

Share This

CGI Perl scripts debugging (solve 500 Internal Server Error)

When you run your perl scripts in browser you would get "500 Internal Server Error" when something goes wrong. There would be several reasons of this but one thing to be done is to check if your perl script contains errors. To do it login to server you're running perl script (I hope you use Linux ;] ) and execute command:

/usr/bin/perl -w /path/to/script.cgi

It will show debug information and it would be much easier to find and solve the problem.

Good luck!

You may also be interested in:
Access to sqlite3 database through perl (script example)

Share This

Access to sqlite3 database through perl (script example)

By publishing this post I try to help people who want to get access to popular and simple database engine sqlite through perl script. I use sqlite to store e-mails statistics at small mail server in order to retrieve information about users' mail activity like average response time, sent and received messages and etc. There is perl script that is used to get this data per every user or get summary statistics. This script is to be run by web server (I use Apache) and has name index.cgi in my case.

Here is part of it:

#!/usr/bin/perl
use DBI;
print "Content-type: text/html\n\n";
print "<html><head><title>perl and sqlite example script</title></head><body>";
$dbh = DBI->connect( "dbi:SQLite:dbname=/tmp/mail_data.db","", "", { RaiseError => 1, AutoCommit => 0 });

my $fst = $dbh->selectall_arrayref("SELECT min(time_1),max(time_1) FROM mail_data");
foreach my $row (@$fst) {
my ($fst_pr,$lst_pr) = @$row;
print "oldest entry in database: ".gmtime($fst_pr)." gmt<br>newest entry in database: ".gmtime($lst_pr);
}

print "</body>";
print "</html>";
$dbh->disconnect;

After you load this example through any web browser (please read your web server’s manual on how to allow cgi/perl script exec, for example here), script will read sqlite database that is located at /tmp/mail_data.db and display minimal and maximal values of field time_1 from mail_data table.

In order to run this script it’s necessary to install perl, sqlite3 and perl-DBI-SQLite cpan module.

You may also be interested in:
CGI Perl scripts debugging (solve 500 Internal Server Error)

Share This



Information Improvisation: Operating system is the backbone for every organization. Having professionals with CISSP certification in organization ensures the life running through its networks. Organizations manage tremendous amounts of traffic due to the use of pc phone and people with 646-058 certifications are ideal for this job. They can also manage online networks which can be hosted on lunarpages, which also provides free email hosting. With the company's logo design every page and a well crafted web template the site can be given a graceful look.