Python Forum
hardest week yet: some guidence please
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
hardest week yet: some guidence please
#21
Have you even tried that code? Do you understand why it's incorrect? Where are the two values you need stored? It really shouldn't be too hard.
Reply
#22
(Aug-18-2019, 06:56 PM)ndc85430 Wrote: Have you even tried that code? Do you understand why it's incorrect? Where are the two values you need stored? It really shouldn't be too hard.

I know its something simple and yes i ran the code this is the output:

Output:
Attackers tried anonymous times to log in as root Attackers tried bin times to log in as root Attackers tried suse times to log in as root Attackers tried bob times to log in as root Attackers tried 89502 times to log in as root Attackers tried 61947 times to log in as root Attackers tried sshd times to log in as root Attackers tried nagios times to log in as root Attackers tried mobile times to log in as root Attackers tried installer times to log in as root Attackers tried adam times to log in as root Attackers tried forum times to log in as root Attackers tried data times to log in as root
As I stated I do not believe that my values (maybe not the correct term) are going in my dictionary and I am certain it is not counting how many times each user attempts to log in. I know you say this should be simple, but please keep in mind I am in an introductory class 5 weeks ago I never wrote code before. I have struggled and spent countless hours on 1 assignment and this forum has helped me tremendously. and I thank everyone for that

updated code so far


intruder_log = {}

with open("auth.log.1") as auth_log:

    for line in auth_log:
        if "Failed password" in line:
            start = line.find("invalid user")
            end = line.find(" from")
            name = line[start + 13:end]

            if name in intruder_log:
                intruder_log[name] += 1
            else:
                intruder_log[name] = 1

            for key in intruder_log:
                print("Attackers tried {1} times to log in as {0}".format(name, key))
Reply
#23
You want the key and value in the intruder_log, so both should be in your for statement (for key, value in....)
Now you have the value as well, which would be the _first_ parameter in your format to get it into the sentence logically.
Do that, run, see what you get. Then you will know if you are counting and eliminating correctly.
Reply
#24
(Aug-18-2019, 11:13 PM)jefsummers Wrote: You want the key and value in the intruder_log, so both should be in your for statement (for key, value in....) Now you have the value as well, which would be the _first_ parameter in your format to get it into the sentence logically. Do that, run, see what you get. Then you will know if you are counting and eliminating correctly.
english plz
Reply
#25
Not meaning to obfuscate, just a reminder that in the Homework forum that goal is to lead you to the answer rather than give you the answer. An "A Ha!" moment is much better for the learning process.
OK, in more detail. In line 16 he is looping through intruder_log, but by using
for key in intruder_log
he is only getting the first value, where he really needs both (the name and the count) so
for name, count in intruder_log:
will pull both values. NOW you can print the results using the format method
Reply
#26
Actually, they both pull two values. It's just that the first one pulls both values into key, where the second one pulls them into two different variables. So key[0] == name and key[1] == count.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Calculating the number of day of the week RbaPhoenix 3 2,433 Mar-27-2020, 09:23 PM
Last Post: Larz60+
  week 1 python help - string formatting ? raymond2688 20 7,627 Jul-09-2019, 08:10 PM
Last Post: snippsat
  Trying to get the week number from a string of numbers fad3r 2 3,159 Apr-15-2018, 06:52 PM
Last Post: ljmetzger

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020