Files
siotp/sisr2/sisr/35-python/reglex/analog.py
2025-11-14 11:51:04 +01:00

21 lines
577 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/python3
import sys
import re
ip_vol = {}
regexp = "^(\S+) (\S+) (\S+) \[([^]]+)\] \"(\w+) (\S+).*\" (\d+) (\S+)"
for line in sys.stdin: # on lit sur lentré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)
if host in ip_vol:
ip_vol[host] += int(byte)
else:
ip_vol[host] = int(byte)
for host in ip_vol.keys():
print ('host : ', host, 'volume : ', ip_vol[host])