473,326 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Loop Iteration

RaH
Hello.

I am writing a script to parse my logfiles to monitor sshd attempted
logins. I know I'm reinventing the wheel, but it's something I want
to do. The problem I am having is that upon the 4th or 5th pass in my
for statement I recieve an error
AttributeError: 'NoneType' object has no
attribute 'group'When I tested against a smaller
version of my logs that contained roughly 8 ip's (one ip appears 6
times another 2) it works fine without the AttributeError.

My question is if it is in my implementation of RE or could it be a
memory issue?

This is a sample of what the log looks like [code:1:eaa2962442]
Dec 25 11:30:17 linux sshd[2198]: Received
disconnect from ::ffff:200.91.12.4: 11: Bye Bye
Dec 25 11:30:18 linux sshd[2199]:
input_userauth_request: illegal user sibylla
Dec 25 11:30:18 linux sshd[2199]: Could not
reverse map address 200.91.12.4.
Dec 25 11:30:18 linux sshd[2199]: Failed password
for illegal user sibylla from ::ffff:200.91.12.4 port
55697 ssh2[/code:1:eaa2962442]

Actual script[code:1:eaa2962442]
import re, string

def main():
match = 'Failed password for illegal user'
pattern = re.compile(match)
f = open('xaf', 'r')

instance = 0
for line in f:
if pattern.findall(line):
this = re.sub(
r'^([a-zA-Z]+)\s*([0-9]+)\s*([0-9]+):([0-9]+):([0-9]+)\s*([a-z]+)\s*([a-z]+)\s*([^0-9]+)\s*([0-9]+)\s*([^0-9]+)',
'', line, 1)

ip =
re.match(r'^(?P<ip>([0-9]+).([0-9]+).([0-9]+).([0-9]))',
this)

of = open("out.txt", 'a')
print ip.group('ip')
instance = instance + 1
of.close()
f.close()

if instance != 0:
print "%s match(s) found for Failed password for
illegal user" % instance
if __name__ == "__main__":
main()
[/code:1:eaa2962442]

Dec 21 '05 #1
1 1223
On Wed, 21 Dec 2005 18:05:22 +0000, RaH wrote:
Hello.

I am writing a script to parse my logfiles to monitor sshd attempted
logins. I know I'm reinventing the wheel, but it's something I want
to do. The problem I am having is that upon the 4th or 5th pass in my
for statement I recieve an error
AttributeError: 'NoneType' object has no
attribute 'group'


At an interactive prompt, type help(re.match) and you will get:
match(pattern, string, flags=0)
Try to apply the pattern at the start of the string, returning
a match object, or None if no match was found.
When there is no match, your loop tries to call None.group. None has no
group attribute, just like the error message says.
--
Steven.

Dec 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alex | last post by:
Compiler - Borland C++ 5.6.4 for Win32 Copyright (c) 1993, 2002 Borland Linker - Turbo Incremental Link 5.65 Copyright (c) 1997-2002 Borland Platform - Win32 (XP) Quite by accident I stumbled...
22
by: Jan Richter | last post by:
Hi there, the Code below shows DJBs own implementation of strlen (str_len): unsigned int str_len(char *s) { register char *t; t = s; for (;;) { if (!*t) return t - s; ++t;
16
by: Claudio Grondi | last post by:
Sometimes it is known in advance, that the time spent in a loop will be in order of minutes or even hours, so it makes sense to optimize each element in the loop to make it run faster. One of...
6
by: drmario | last post by:
Here's what I got: ifstream File; // already initialized and associated with a file input stream unsigned short r = 1; // a counter to tell me if this is the loop's first iteration ...
1
by: greyseal96 | last post by:
Hi, I am a pretty new programmer, so I apologize in andvance if this is a dumb question... In a book that I'm reading to learn C#, it says that when using a foreach() loop, a read-only copy of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.