Skip to main content

Posts

Showing posts from June, 2007

Parsing Commandline Options in Perl

Anyone who has tried to parse command-line options in Perl knows how messy the process gets with increasing number of options. Luckily, there are some modules that the whole process more manageable. The tutorials I am learning from are http://systhread.net/texts/200704optparse.php#one and http://aplawrence.com/Unix/perlgetopts.html . Without using a special Perl module, options can be parsed as follows (credit to http://systhread.net/texts/200704optparse.php#one ) while ( my $arg = shift @ARGV ) { if ( $arg eq '-F' ) { $F_FLAG = 1; } elsif ( $arg eq '-f' ) { $FILE_ARGUMENT = shift @ARGV; } elsif ( $arg eq '-u' ) { usage(); } else { usage(); exit 1; } } Ultimately, using the getopt module should be done if it is available, why reinvent the wheel? Here is an example of using the Getopt module: use Getopt::Std; ... getopt ('f:uF'); die "Usage: $0 [ -f filename -u ]\n" unless ( $opt_f or $opt_u ); if ($opt_f) {

Intro to OOPerl

Excellent set of basic notes can be found as Part 1 and Part 2 The main reason I am interested in learning it is to enable me to use some important Perl modules/packages effectively. In particular, I want to use the PerlMol package to clean up some of my scripts.

Checking Perl Library Path and Modifying it

It is contained in an array @INC, so checking it would be as easy as printing that array. One can add or subtract items to this array to include of exclude some libraries using array manipulating tools like shift/unshift/chop/pop/push/splice/ ... . Here is a script demonstrating that. !#/usr/bin/perl -w #Prints Perl library path and modifies it: print "Default Perl library path:\n@INC\n"; push(@INC, "/home/user/lib/perl"); print "New Perl library path:\n@INC\n"; And the output was: Default Perl library path: /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl . New Perl library path: /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl . /home/user/lib/perl BTW: I brushed up on Perl basics from this great resource: http://www.pa

IPtables, SVN, and NMAP

I reviewed some material on IPtables, SVN, and NMAP just for the sake of keeping my mind busy. Here are some useful notes: IPtables - best resource found at HERE SVN - best, as in the quickest and simplest intro could be found HERE NMAP - I honestly don't see in using it for more than port-scanning in a few instances. Anyway, here are a few other options that might come in handy at some point. nmap -sT/sS/ sX/sF/...[-P0] IPADDRESS(range) == to check which ports are open nmap -sP IPADDRESS(range) == a simple ping scan for availability nmap -sO IPADDRESS(range) == check what IP protocols are available nmap -sV IPADDRESS(range) == a scan with version detection Other useful flags: -O == detects OS, part of -v (verbosity) flag as well -A == detects OS and versions -v == request high verbosity/detail -F == performs a fast scan of only a few common ports Installing Perl modules Perl modules may be installed using the CPAN module or from source. SOURCE

No Update

My only update is that there is no update. This is not merely a play of words -- it is true! Days are going by without anything eventful happening to me. Nothing worthy of reporting at all. Sad days really. In the spirit of keeping this blog up-to-date, I hereby report that there is no update.

Tips and Tricks

Since there ain't a whole lot happening in my life, I might as well use this venue to make a list of cool Linux tips and tricks. 1) Hey, I need to start spending less time reading Lakers rumors. Why not start by blocking access to the Lakers forum I frequent most, namely forums.lakersground.net (64.38.208.184). Here is how it's done using iptables . iptables -I INPUT -s 64.38.208.184 -d 0/0 -j REJECT 2) If you would like to view your iptables filters/instructions, you can just type iptables -L 3) To check which ports are open, one can use nmap as nmap -sT localhost OR nmap -A -sT localhost OR nmap -sT IPaddress 4) To convert OGG to MP3, use ~/bin/ogg2mp3.pl More to come

Camping out

in Hunting Island State Park in South Carolina. I love camping, especially when everything is kept very simple and organic. I always hoped to live a simple life far away from civilization and camping is the closest to that lifestyle for the time being. As anyone would expect, I missed not checking my email and was desperate to read some good news after four days w/o internet access. Unfortunately, all I got was loads of spam, with a few exceptions. Well, so much more to say and so little time to do it. I am out.