Created
July 17, 2019 11:27
-
-
Save bugcy013/bf6594f9313f51467c4bf5ccaad9105b to your computer and use it in GitHub Desktop.
Apache / Httpd Logs Regex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| __author__ = 'dhana013' | |
| import re | |
| LOG_REGEX = '(?P<ip>[(\d\.)]+) - - \[(?P<date>.*?) -(.*?)\] "(?P<method>\w+) (?P<request_path>.*?) HTTP/(?P<http_version>.*?)" (?P<status_code>\d+) (?P<response_size>\d+) "(?P<referrer>.*?)" "(?P<user_agent>.*?)"' | |
| line = '172.183.134.216 - - [12/Jul/2016:12:22:14 -0700] "GET /wp-content HTTP/1.0" 200 4980 "http://farmer-harris.com/category/index/" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; rv:1.9.3.20) Gecko/2013-07-10 02:46:11 Firefox/9.0"' | |
| compiled = re.compile(LOG_REGEX) | |
| match = compiled.match(line) | |
| data = match.groupdict() | |
| print data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment