Skip to content

Commit 22ec957

Browse files
author
devcoder
committed
Log file parser and ip finder
1 parent 524b2f9 commit 22ec957

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Rishabh/parse_log_files_find_ip.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import os
2+
import re
3+
4+
path = 'path/to/the/directory/'
5+
6+
files = []
7+
8+
for r, d, f in os.walk(path):
9+
for file in f:
10+
if '.log' in file:
11+
files.append(os.path.join(r, file))
12+
13+
ip_addr=[]
14+
for fn in files:
15+
with open(fn) as f:
16+
for line in f:
17+
var = re.findall('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', line)
18+
if var:
19+
ip_addr.append(var)
20+
21+
print(ip_addr)
22+
23+

0 commit comments

Comments
 (0)