nouveau fichier : stat_log.py
This commit is contained in:
parent
e4d5860326
commit
26bc9b9710
189759
sio2/SISR/07-python/access.log
Normal file
189759
sio2/SISR/07-python/access.log
Normal file
File diff suppressed because it is too large
Load Diff
30
sio2/SISR/07-python/stat_log.py
Normal file
30
sio2/SISR/07-python/stat_log.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import re
|
||||||
|
|
||||||
|
volip = {}
|
||||||
|
cptip = {}
|
||||||
|
regexp = "^(\S+) (\S+) (\S+) \[([^]]+)\] \"(\w+) (\S+).*\" (\d+) (\S+)"
|
||||||
|
for line in sys.stdin: # on lit sur l’entrée standard
|
||||||
|
line = line.rstrip () # on enleve le retour ligne
|
||||||
|
res = re.match (regexp, line)
|
||||||
|
if res:
|
||||||
|
(host, rfc931, user, date, request, url, status, byte) = res.groups()
|
||||||
|
host = res.group (1)
|
||||||
|
byte = res.group (8)
|
||||||
|
# print ('host : ', host, ' byte : ', byte)
|
||||||
|
if host in volip:
|
||||||
|
volip[host] +=int(byte)
|
||||||
|
else :
|
||||||
|
volip[host] =int(byte)
|
||||||
|
if host in cptip:
|
||||||
|
cptip[host] +=1
|
||||||
|
else :
|
||||||
|
cptip[host] = 1
|
||||||
|
|
||||||
|
for host in volip.keys():
|
||||||
|
print (" Lhote" , host , " : ", volip[host])
|
||||||
|
|
||||||
|
for host in cptip.keys():
|
||||||
|
print ("L'hote " , host, "s'est connecté ", cptip[host], "fois")
|
Loading…
x
Reference in New Issue
Block a user