Python Forum
test..and I'm already lost - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: test..and I'm already lost (/thread-8477.html)



test..and I'm already lost - sannixinc - Feb-22-2018

Hi all, i have to create a log scanner or python script that will run through a .txt file, and it should create a text file that reads all rows in the file and searches for certain text, and gives me the following summarized info after the analyzation of said log file:
- Displays a count of how many scan events occurred in the logs
- Displays a list of all host ip addresses where the scans originated from
- Displays a list of all host ip addresses where the scans were performed against

I have created the python file itself, but that's about as far as i got. Unfortunately, my teacher is terrible at responding to questions, so i shall resource to the all knowing internet.

here is what i have so far:
import os
import re

filePath = "./ssh.log.txt"
fd = open(filePath, 'r')

with fd as reader :
    for line in reader :
        print( line )
Here are two samples of the file: (Text box breaks it into two lines)ANY HELP WILL BE GREATLY APPRECIATED! THANKS GUYS!

1331902037.460000 CzOW1hqdnsStTLdB2 192.168.202.79 46073 192.168.229.101 22 undetermined INBOUND SSH-1.5-Nmap-SSH1-Hostkey SSH-2.0-OpenSSH_5.8p1 Debian-7ubuntu1 - - - - -

1331902037.730000 COIlCg1sDKjduod1e8 192.168.202.79 46085 192.168.229.101 22 failure INBOUND SSH-2.0-Nmap-SSH2-Hostkey SSH-2.0-OpenSSH_5.8p1 Debian-7ubuntu1 - - - - -


RE: test..and I'm already lost - glidecode - Feb-22-2018

Have you found a python function to search for specific text string? otherwise you have to make that part yourself, maybe with a loop.

If you always have the IP adress in the same part/position of the lines, you read each line into a list and then refer to the IP part of the list by position as:
[python]list5[0:9]/python]
for the first 10 characters