[Tutor] IP address parse

Que Prime queprime at gmail.com
Sun Aug 10 06:57:27 CEST 2008


I'm trying to parse a log file for all ip addresses but can't get my RE to
work.  Thanks in advance for pointing me in the right direction


#IP address parse

##############################
import re

infile = open("host0_declare.txt","r")
outfile = open("out.txt","w")

patt = re.compile(\[0-9]{1,3})\.(\[0-9]{1,3})\.(\[0-9]{1,3})\.(\[0-9]{1,3})

for line in infile:
  m = patt.match(line)
  if m:
    outfile.write("%s.%s.%s.%s\n"%m.groups())

infile.close()
outfile.close()
#############################
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080809/c36e7d44/attachment.htm>


More information about the Tutor mailing list