Hi,
I'm trying to parse an apache log file and match the IP addresses in it. This is my code so far:
import re
ippattern = re.compile(r"\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b")
def matchmyip():
if ippattern.search(line):
matchedip = ippattern.search(line)
print matchedip.group()
Now given a line like this from a log file:
1999-08-01 00:00:00 212.67.129.225 - W3SVC3 PROWWW01 194.128.73.195 GET /entrance/V0_1/default.asp bhcd2=933465599 302 0 497 396 15 80 HTTP/1.1 Mozilla/4.0+(compatible;+MSIE+4.01;+Windows+95;+FREESERVE_IE4) bhCookie=1;+ASPSESSIONIDGGGGGRDN=PPLCJMKDDJBMPIMEAEDPIJGF -
my regular expression only matches the first ip address but not the second one. How should I modify my regex so that it matches multiple occurences of the same pattern in a single line?
Thanks,
Adi