Write and test a simple perl program on the linux platform, Programming Languages

Assignment Help:

Write and test a simple perl program on the linux platform.  You may use any linux system you wish, including the Suse linux installed in the lab.

Activities.

Note:  to run linux in the lab use Vmware Workstation to run the virtual machine "Clone of OpenSuse 12.1"

Your program is going to function like the linux "ifconfig" command that is used to obtain information about network interfaces.  You will have to install the Net::Int::Stats and Net::Ifconfig::Wrapper packages using CPAN.  The CPAN documentation for the packages explains how the packages are used.  When you run CPAN on the computers in the lab you must run it with root privileges.  First, open a command prompt.  On the lab computers the command prompt is called XTerm and is listed in the menu under System Tools.  At the prompt enter

sudo perl -MCPAN -e shell

you will be asked for the root password, which is "tcpip".   CPAN may ask for detailed configuration.

The linux ifconfig command can also be used to configure network interfaces, and, with no parameters will display information about all of the available interfaces.  Our program will not be able to set information, and will expect an interface name as a parameter.  It will then display information similar to what would be obtained by a command like "ifconfig eth0".

To run the ifconfig command on the computers in the lab you must run the command with root privileges.  First, open a command prompt.  At the prompt enter

 

sudo /sbin/ifconfig

 

you will be asked for the root password, which is "tcpip".

The Net::Int::Stats package has a constructor method called "new" which returns an object reference

 $get_Iface_data = Net::Int::Stats->new();

A method of this object can be used to retrieve information about an interface like this

my $Iface     = $ARGV[0];

my $rx_packets  = $get_Iface_data->value($Iface, 'rx_packets');    

The Net::Ifconfig::Wrapper package returns a complicated hash ref, from which information about an interface can be extracted.  This statement gets the hash ref:

my $Iface_Info = Net::Ifconfig::Wrapper::Ifconfig('list', '', '', '');

Then statements like these provide access to the data:

print "\tether ". $Iface_Info->{$Iface}{'ether'}."\n";

In this statement $Iface_Info is a hash ref, $Iface_Info->{$Iface} refers to the data in the hash corresponding to the key value contained in $Iface.  That data is also a hash, and

$Iface_Info->{$Iface}{'ether'} refers to the data in this hash corresponding to the key value 'ether'.

This statement gets address and mask values, and since an interface can have more than one address it has to loop through a list contained in a hash, like the example in slide  21 of lecture 4:

while (my ($Addr, $Mask) = each(%{$Info->{$int}{'inet'}}))

      { print "\tinet $Mask $Addr"; };


Related Discussions:- Write and test a simple perl program on the linux platform

Outline the norms to be designing a web page, Question: (a) Outline th...

Question: (a) Outline the six norms to be considered before designing a Web page. (b) Write a program such that when a user right-clicks anywhere on a Web page, the follow

Create xml documents to contain well-defined information, The objectives of...

The objectives of this assignment are to test your ability to create XML documents to contain well-defined information. This assignment will be used further in Assignment 2, so ple

Shell script, append two text files vertically

append two text files vertically

Programming code for supermarket software , The software development team i...

The software development team identified the following classes based on the analysis of given requirements: Product, Employee, ProductList, Supplier. 1.  Identify the relationsh

Program that will allow to print grade list of student, We want a program t...

We want a program that will allow us to print a "grade list" of the students in a class. The program should loop, asking for a name, midterm score, and final score. It should th

Python, Write a function lastfirst() that takes a list of strings as a para...

Write a function lastfirst() that takes a list of strings as a parameter. Each string in the list has the format ''Last, First'' where Last is a last name and First is a first nam

Microsoft intermediate language in .net, Microsoft Intermediate Language in...

Microsoft Intermediate Language in .NET When you create value in any terminology and gather, it will be changed to an 'Intermediate Language' (Microsoft Advanced Language - MSIL

Sql vb integration, I need an application that will gather data from one SQ...

I need an application that will gather data from one SQL Database and update another. Data is contained in dbo.CallList with following fields: Customer_ID, AlreadyPickedUp, Phone_N

Define the procedures cons, Show that we can represent pairs of nonnegative...

Show that we can represent pairs of nonnegative integers using only numbers and arithmetic operations if we represent the pair a and b as the integer that is the product 2 a 3 b .

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd