Intrvw: Difference between revisions
→AMZN SysDE
(→MS) |
|||
Line 383:
<pre>
#Read the file
f = open('/var/log/apache2/access.log','r')
lines = f.readlines()
f.close()
print(len(lines))
# Append Response code & Dest IP address to 'a'
a = []
for i in lines:
a.append((i.split()[0], i.split()[8]))
print(len(a))
# Create a set of IP addresses 'b'
for i in a:
b.append(i[0])
Line 400 ⟶ 404:
b = set(b)
print(len(b))
# Create a new list having Unique IP addresses & list of Responses for each:
▲c =[]
c=[]
for i in b:
x = []
for j in range(len(a)):
if i == a[j][0]:
x.append(a[j][1])
c.append((i,x))
print(len(c))▼
▲len(c)
# Print the results:
for k in range(len(c)):
print(c[k][0],len(c[k][1]))
</pre>
|