The objective is to demonstrate proficiency with reading files, and using string methods to slice strings, working with dictionaries and using-step wise development to complete your program. Step 1 The objective of this program is simply to open a file, read each line and display it. Your program should: Open auth.log.1b. (See note below). Read each line. Display each line. Note that your program could take over 15 seconds to complete. Save this program as step_1.py. Notes:  Download auth.log.1b  Download auth.log.1bby right clicking on it and doing a ‘Save as’ to the same directory in which you have your program. Although auth.log.1b is a plain text file, the ‘.1b’ file extension is non-standard and will not be recognized as a particular file type. You can view it, if you like, in any text editor such as NotePad, TextEdit or IDLE, but you may have to select ‘All file types’ to open it.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

The objective is to demonstrate proficiency with reading files, and using string methods to slice strings, working with dictionaries and using-step wise development to complete your program.

Step 1

The objective of this program is simply to open a file, read each line and display it. Your program should:

  • Open auth.log.1b. (See note below).
  • Read each line.
  • Display each line.
  • Note that your program could take over 15 seconds to complete.

Save this program as step_1.py.

Notes: 

Download auth.log.1b  Download auth.log.1bby right clicking on it and doing a ‘Save as’ to the same directory in which you have your program. Although auth.log.1b is a plain text file, the ‘.1b’ file extension is non-standard and will not be recognized as a particular file type. You can view it, if you like, in any text editor such as NotePad, TextEdit or IDLE, but you may have to select ‘All file types’ to open it.

      •  

Step 2 

The objective of this step is to recognize which lines indicate an attack. Start this step by making a copy of your Step 1 program.

Your program should do the following:

  • As each line is read, check to see if “Failed password” is in the line by using the ‘in’ operator.
  • If “Failed password” is in the line, display the line.
  • Otherwise do not.

Save this program as step_2.py.

Potential gotchas

  • If your program is not finding any lines, make sure you have the case right. “Failed password” and “failed password” are different.
  • Also, be mindful of spelling.

Step 3 

This step is perhaps the most challenging. The objective here is to slice the user name out of the lines that include “Failed password”. Begin by making a copy of step_2.py.

Strategy:

You will slice the user name, which varies in length and start position within the line, by finding a pattern that always appears immediately before it and another pattern that always appears immediately after it. Use these offsets to compute the starting and ending values of the user name slice.

Your program should do the following:

  • For just the lines that include “Failed password”:
    • Use the string find() method to get the offset of “invalid user ” from the start of the line.
    • Determine the starting point of the user name slice by adding the length of “invalid user “ to the offset provided by find(). This will be the index of the first character in the user name.
    • Use the string find() method to get the offset of “ from “. This will serve as the end point of the user name slice.
    • Slice the user name from the line using the starting and ending points and store the result in a variable.
    • Instead of displaying the whole line, just display the slice. You should see ‘root’ displayed quite a bit.

Save your program as step_3.py.

Step 4 

The objective of this step is to use a dictionary to count the number of times each user name appears in attack attempts. Begin by making a copy of step_3.py.

Strategy:

Up until this point, you've been working with an abbreviated log file, auth.log.1b, which only has data for attacks from user root. For this step, you'll need the full log file: auth.log.1.   Download auth.log.1. Download it just as you did with auth.log.1b and change your code to open auth.log.1 instead of auth.log.1b. Note that your program could take considerably longer to run using auth.log.1.

Use a dictionary to count the number of times each user name appears in the file. The items in the dictionary will consist of a user name as the key and a count as the value.

Your program should do the following:

  • Create an empty dictionary at the top of the program right after the header comments.
  • After you have sliced a name, use the in operator to see if it is already in the dictionary
  • If it is not in the dictionary, add it. Do so by using the user name as the key and set the value to 1.
  • If it is in the dictionary, use the user name as a key to get the current value. Add 1 to the current value and store it back in the dictionary.
  • After all of the lines of the file have been read, use a for loop to display each key and value. The key will be a user name and the value will be the number of times the user name appears in the dictionary.

Save your file as hwk6.py

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY