|
|
楼主 |
发表于 2017-12-24 12:08:22
|
显示全部楼层
统计日志中访问ip地址个数:% P [2 W2 D' q: M3 x
, ~- h( U8 I' b; q
# vim tongjiip.py
/ D% o! f/ @5 ?2 I4 b+ h! i+ K4 e! e( _
#!/usr/bin/env python2 c0 C- R$ U @3 A
#!coding=utf-81 s0 R) Y" c, \ @& o. G
list = []& D! K# F6 K- @) x$ ]0 u
f = file('/var/log/httpd/access_log')
% h* ~: P, g. m w& Qstr2 = f.readlines()& n7 \9 n; e b
f.close()$ q3 n% h6 S' C, F6 l7 r* f
for i in str2:$ T% H0 `5 H3 z
ip = i.split()[0]
4 g5 u8 B& U$ w4 x" ? list.append(ip)
$ V+ _+ q6 x9 D5 Mlist_num = set(list)
$ r6 s8 G) E6 y0 o8 _; ]for j in list_num:6 `7 g8 `# s: H5 C. M4 u$ _) \
num = list.count(j)4 d9 z- x, c6 q& M o7 v! G
print '%s :%s' %(j,num)& T; u8 z& ?0 \( R* ~$ x
|
|