Objective Create a program that provides a management and monitoring service. Specifications The program must support the following command line arguments: ./sysman [--sysinfo] [--ps] [--exec ]...

Objective



Create a program that provides a management and monitoring service.


Specifications


The program must support the following command line arguments:


./sysman [--sysinfo] [--ps] [--exec ] [--listen ]


These options are as follows:



  • --sysinfo should display the following information about the system: number of users, available memory.

  • --ps should display a table of the current list of processes, including pid, name of executable, owner of process, physical memory consumed by process (RSS), cumulative CPU time.

  • --exec should execute the requested command and display the result. The command must be provided as a single quoted string, like this:


./sysman --exec 'ls -l /home'



  • --listen should start the program in server mode. It should open a TCP server socket on the specified port and handle incoming connections as described in “Server Mode” below.


The options are mutually exclusive: only one will be supplied. I will not test your program with more than one option at a time.


Server Mode


When a client connects to the port sysman is listening on, sysman should display a one-line greeting of your choice, and then read a line from the client with a command as follows:



  • SYSINFO

  • PS

  • EXEC

  • QUIT


sysman should perform the requested operation and send the resulting output back to the client.



  • The EXEC command here will be executed without quotes (example):


EXEC ls -l /home



  • The QUIT command should cause sysman to close the connection.


To test server mode, launch sysman with the –listen option, then use the nc command to communicate with it interactively (i.e., don’t use echo piped to nc, as you did in project 1). For example, in one terminal, execute:


./sysman --listen 6000


In another terminal, execute:


nc localhost 6000


Welcome to sysman!


SYSINFO


2 users, 1023232 bytes available


PS


... table here ...


EXEC ls -l /home


... output of ls here ...


QUIT


Part 1


Implement the specifications listed above.



  • You may write your program in either Python or C.

  • If you write your program in Python (call it sysman.py), you must provide a bash script named sysman that launches the Python program, passing through any command line arguments

  • If you write your program in C, provide a Makefile that creates an executable named sysman.

  • For full credit, the EXEC command must stream the output of the command to the client as it is generated, rather than all at once after the command completes.


Design Requirements



  • Create a class with methods to obtain system information, obtain the list of processes, and execute a command, streaming the result to the supplied output stream. The methods of the class should output information to a stream/file parameter. If you are writing in C, create a library of functions in a separate file.

  • In your main program, implement the command line processing and the logic for the server. Use the Python class/C library to perform the work requested by the command line arguments and/or remote client.


Part 2


In this enhancement, sysman, when running in server mode, will support network monitoring when the --monitor command line argument is supplied:


./sysman [--sysinfo] [--ps] [--exec command] [--listen ] [--monitor ::]


For example:


./sysman --listen 6000 --monitor 1.2.3.4:5.6.7.8:7000


will cause sysman to analyze incoming packets. For each incoming packet whose source IP address is 1.2.3.4 (srcipaddr), sysman will send a UDP message to 5.6.7.8 (logipaddr), port 7000 (logport). The format of the UDP message should be as follows:




where  and  is the date and 24-hour time (see format below),  is the IP address that matched, and is the packet size.


Example:


2020-04-17 17:05:00 1.2.3.4 26


To perform the network packet monitoring, create a background thread to launch tcpdump and process its output in real time. Use the following options for tcpdump:


tcpdump --immediate-mode -l -q --direction=in -n ip


Notes:


tcpdump must be executed with root permission in order to capture packets. When experimenting with tcpdump from the command line, run using sudo. When invoking tcpdump from your program, don’t use the sudo command (which may prompt for credentials and thus cause issues); instead, run your program using sudo.


To test that your program is properly transmitting the packets, I recommend executing sysman like this:


./sysman --listen 6000 --monitor 1.2.3.4:localhost:7000


Change the 1.2.3.4 IP address to the source IP address that you see used when you use tcpdump from the command line in testing to dump the traffic being transmitted to the computer where you will run sysman.


Then, launch the nc utility on the same computer where sysman is running to receive the UDP packets:


nc -ul 7000


You should see output indicating that nc is receiving the data being transmitted by your sysman utility.


Part 3


Enhance sysman to handle multiple concurrent remote clients. When each client connects or disconnects, the server should output a message indicating connect/disconnect, and how many clients are currently connected.


Part 4


In your logic for the ps command, obtain process information by reading it from the /proc filesystem instead of running a utility like ps.


Other Requirements



  • Use good coding style. Organize your program into clearly documented functions. Include a header comment at the top of the source files; use good variable names, an indentation width of4 spaces, good whitespace, etc.




May 18, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here