Translate

Image of Modern Operating Systems (3rd Edition)
Image of RHCE Red Hat Certified Engineer Linux Study Guide (Exam RH302) (Certification Press)
Image of Linux Kernel Development (3rd Edition)
Image of Operating System Concepts

Using Perl Net::IP to Manipulate IPv4 Addresses

In a previous post, I demonstrated a Korn shell script which determined the subnet mask for a range of IPv4 addresses. Perl has a module called Net::IP which provides a number of functions which can be used to manipulate IPv4 (and also IPv6) addresses to provide the same information and a lot more besides. For example, the following code outputs a lot of information about a classless prefix: use Net::IP; my $ip = new Net::IP (‘10.1.1.0/24’) or die (Net::IP::Error()); print ("IP : ".$ip->ip()."n"); print ("Sho : ".$ip->short()."n"); print ("Bin : ".$ip->binip()."n"); print ("Int : ".$ip->intip()."n"); print ("Mask: ".$ip->mask()."n"); print ("Last:

Calculating Prime Numbers using Perl

Definition of a prime number: A prime number is defined by any number that is only dividable by 1 or itself. Except for 2 which is a prime, a prime number is always odd (2n+1) Here is a Perl script which outputs all the prime numbers between 0 and 10000: #!/usr/bin/perl my $UPPER = 10000; my $sieve = “”; print “2n”; for (my $guess = 3; $guess < = $UPPER; $guess+=2) { next if vec($sieve,$guess,1); print "$guessn"; for (my $mults = $guess * $guess; $mults