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

CMIS 102, Calculate the total price based on several key parts required to ...

Calculate the total price based on several key parts required to build a state-of-the-art gaming computer. The user will have the option of selecting different parts.

Use a procedure to integrate cube, Simpson's Rule is a more accurate method...

Simpson's Rule is a more accurate method of numerical integration than the method described in class. Using Simpson's Rule, the integral of a function f between a and b is approxim

Prepare notes on the logical storage manager, Question: (i) Prepare bri...

Question: (i) Prepare brief notes on the Logical Storage Manager. (ii) Show benefits that can be achieve by using the LSM Manager. (iii) LSM organizes and optimizes disk

Shell script to find a particular pattern from the file, Normal 0 ...

Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4

JUnit test, hi, can you help me with testing java classes I have wrote usin...

hi, can you help me with testing java classes I have wrote using java and jsp and servlet in eclipse ? I want to use JUnit for testing

Java input stream, Expertsmind brings you unique solution in java assignme...

Expertsmind brings you unique solution in java assignments I.O streams The Java.io packages contains nearly every category you might ever need to execute feedback and resu

Cookies management with perl, One of the main strengths of the Perl program...

One of the main strengths of the Perl programming language are its powerful text manipulation features. In this assignment, you will put them to  use for writing a Perl program tha

Pseudo code, I need help putting this into a flowchart constant c as Intege...

I need help putting this into a flowchart constant c as Integer = 3500 Constant CALORIESTOOUNCE as Integer = 219 Declare Sex as Character Declare Age as Integer Declare Weight as I

Shell script to change the permission of a file, Normal 0 false...

Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4

Windows card space, Windows Card Space Windows Card Space (codenamed Info C...

Windows Card Space Windows Card Space (codenamed Info Card), is Windows now-canceled customer application for the Identification Met system. Card Place is an instance of a class of

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