Ajout du tp de python et regex

This commit is contained in:
2025-11-14 14:17:17 +01:00
parent 522b01ef35
commit b3721a511b
5 changed files with 75 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
#!/usr/bin/python3
import sys
import re
regexp = "^(\S+) (\S+) (\S+) \[([^]]+)\] \"(\w+) (\S+).*\" (\d+) (\S+)"
cpthost={}
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)
#print ('host : ', host, ' byte : ', byte)
if host in cpthost:
cpthost[host]++int(byte)
else:
cpthost[host]=int(byte)
for host in cpthost.keys():
print(host, " ",cpthost[host])