Python - splitting a log and searching for something specific -


i have assignment , wondering if help. part of question required analyse system log. log contains information such time , date, if root access attempted , ip address attempt came from.

my question is: how loop through log , pull out ip addresses.

myfile = open('syslog','r')  line in myfile.readlines(): list_of_line = line.split(' ') 

so here i've split list how can loop through trying locate ip address. have used locations isn't practical looks 1 address. want search through , find addresses mean looking strings length e.g. xxx.xxx.xx.xx ip address , specify looking numeric values.

edit-

jan 10 09:32:07 j4-be03 sshd[3876]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=218.241.173.35  user=root jan 10 09:32:09 j4-be03 sshd[3876]: failed password root 218.241.173.35 port 47084 ssh2 jan 10 09:32:17 j4-be03 sshd[3879]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=218.241.173.35  user=root jan 10 09:32:19 j4-be03 sshd[3879]: failed password root 218.241.173.35 port 47901 ssh2    jan 10 09:32:26 j4-be03 sshd[3881]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=218.241.173.35  user=root jan 10 09:32:29 j4-be03 sshd[3881]: failed password root 218.241.173.35 port 48652 ssh2 

i've been told ignore line containing pam_unix , focus on line containing "failed password root" duplicate entries. try regular expression 1 although don't understand going on.

import re myfile = open('syslog','r')  ip = re.findall( r'[0-9]+(?:\.[0-9]+){3}', myfile.read() ) print ip 

don't love python?


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -