Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, So, I'm trying to slice the username, root from each line that comes from a text file, but I had no success on getting

Hi,

So, I'm trying to slice the username, "root" from each line that comes from a text file, but I had no success on getting my program assignment to do so. First, I need to find and get the offset of "invalid user" from the start of the line. Then, I have to check the starting point of username, "root" by adding the length of "invalid user" to the offset given via "find()" method, which should be the index of the first character of "root". Then, I have to use the same method as above for the word, "from", which are on those same lines. At this point, I have to slice the user name from the line using the starting and ending points and store the result in a variable. The end result should be able to display the sliced username, "root", which is the problem that I'm having. Can you help me try to resolve this matter? I attached the text file and my program to look at. Thank you.

image text in transcribedimage text in transcribed
File Edit Format Run Options Window Help Apr 9 06:36:54 homer sshd [20345]: message repeated 2 times: [ Failed password for invalid user root from 123.183. 209.134 port 15634 ssh2] Apr 10 06:36:54 homer sshd [20345]: message repeated 2 times: [ Failed password for invalid user root from 123. 183. 209.134 port 15634 ssh2] Apr 10 06:37:03 homer sshd [20347] : pam_unix (sshd: auth) : authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=116. 31.116.46 user=root Apr 11 06:36:54 homer sshd [20345]: message repeated 2 times: [ Failed password for invalid user root from 123. 183. 209. 134 port 15634 ssh2]with open ('wopro. txt', 'r' ) as file: for lines in file: if 'Failed password' in lines: contents = for 'Failed password' in contents: no user = txt. find ('invalid user , 60, 75) no words = txt. find ('from' , 70, 80) print (no user, no words) file. close ()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transport Operations

Authors: Allen Stuart

2nd Edition

978-0470115398, 0470115394

Students also viewed these Programming questions