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

Design a mobile web browser..., HOW CAN I DESIGN A MOBILE WEB BROWSER LIKE ...

HOW CAN I DESIGN A MOBILE WEB BROWSER LIKE OPERA MINI. USING VISUAL BASIC? HELP ME.

Shell script display time for user which is idle, Normal 0 fals...

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

Program for adding a course in the website of a university, 1. You are work...

1. You are working as a designer for a university that offers a program in Computer Science. One of the tracts is computer security. One of your colleagues has recommended adding a

Shell script to check a given number is palindrome or not, Normal 0 ...

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

Linux Lab Assignments, I have a linux lab class that consist of 1 lab assig...

I have a linux lab class that consist of 1 lab assignment per week for 5 weeks. It is an online virtual lab and is fairly easy, I just don''t have the time.

Network security, Term project (you should code a function), demonstrate it...

Term project (you should code a function), demonstrate it to the class and a very breief report (one or two pages) describing what you did. You determine your project (could be imp

Shell script for to change & display system prompt and path, Normal 0 ...

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

NETLOGO , THERE IS ANY1 COULD HELP ME WITH NETLOGO WORK

THERE IS ANY1 COULD HELP ME WITH NETLOGO WORK

Differences between user and kernel level threads, Question : (a) Many ...

Question : (a) Many systems provide support for both user threads and kernel threads, resulting in different multithreading models. What are the two differences between user

Recursive decent parser, Given grammar Grammar M following: 1 - - > b...

Given grammar Grammar M following: 1 - - > begin end 2 - - > 3 - - > 4 - - > ? 5 - - > Id : = ; 6 - - > read ( ) ; 7 - - > write ( )

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