Pages

Here’s a more useful example of using them to test IP addresses for validity.

To belabor the obvious: IP addresses are 32 bit values written as four numbers (the individual bytes of the IP address) separated by dots (periods). Each of the four numbers has a valid range of 0 to 255.

The following bash script contains a bash function which returns true if it is passed a valid IP address and false otherwise. In bash speak true means it exits with a zero status, anything else is false. The status of a command/function is stored in the bash variable “$?”.

If that test passes then the code inside the if statement separates the subject IP address into four parts at the dots and places the parts in an array:

OIFS=$IFSIFS=’.’ip=($ip)IFS=$OIFS

It does this by momentarily changing bash’s Internal Field Separator variable so that rather than parsing words as whitespace separated items, bash parses them as dot separated. Putting the value of the subject IP address inside parenthesis and assigning it to itself thereby turns it into an array where each dot separated number is assigned to an array slot. Now the individual pieces are tested to make sure they’re all less than or equal to 255 and the status of the test is saved so that it can be returned to the caller:

If you are using modules you need to load these first: modprobe loop;modprobe cryptoloop;modprobe cipher-aes Basically you: losetup -e ...

MooLux is a Live USB Linux distribution based on Slackware that utilizes the KDE desktop environment. MooLux is a portable operating system that can be taken with you containing tools for Internet browsing, email, chat, multimedia, office and software for C, Python, Perl programming tasks.
Send your tips to moodjair@moolux.org