【发布时间】:2016-08-09 10:41:48
【问题描述】:
例如我有这个简单的 apache 日志:
192.168.1.1 GET /index.php
192.168.1.1 GET /pilt.png
192.168.1.1 GET /index.php
192.168.1.5 GET /index.php
192.168.1.5 GET /pilt.png
192.168.1.7 GET /index.php
192.168.1.7 GET /index.php
192.168.1.7 GET /index.php
192.168.1.7 GET /kaust/index.php
192.168.1.7 GET /index.php
我将如何编写 Python 代码来整理出所有相似的 IP 地址都在一起并计算有多少 IP 地址
w = open("C:\\Users\\xxx\\Desktop\\test.txt","r")
for i in w:
log=i.split(' ')
print log[0]
w.close()
尝试了这么多,但无法进一步编写代码。
谢谢!
【问题讨论】:
-
您需要对 IP 地址进行排序和所有唯一 IP 地址的功能。对吧??
-
你能告诉我们你到底想要什么输出吗?
-
这是一本字典,我猜是 192.168.1.1 : 3 192.168.1.5 : 2 等等
标签: python apache python-2.7