python练习 根据日志中的ip和url排序
#!/usr/bin/env python
#coding:utf-8 def open_file(file_name):
res={}
with open(file_name) as f:
for line in f:
tmp=line.split(' ')
# print tmp
ip,url=tmp[0],tmp[6]
# print ip,url 以元组的形式存到列表中
res[(ip,url)]=res.get((ip,url),0)+1
return sorted(res.items(),key=lambda x:x[1],reverse=True)
#print open_file('log1.log') def get_htmlstr(arr):
#拼接字符串
tmp1='<tr><td>Num%s</td> <td>%s</td> <td>%s</td> <td>%s</td></tr>'
html_str='<table border="1px">'+tmp1%('名次','IP','URL','COUNT')
for index,value in enumerate(arr[:10]):
html_str+='<tr><td>Num%s</td> <td>%s</td> <td>%s</td> <td>%s</td></tr>' %(index,value[0][0],value[0][1],value[1])
html_str+='</table>'
return html_str
def write_html(file_name):
res=open_file(file_name)
with open('res2.html','w') as f:
f.write(get_htmlstr(res))
write_html('log1.log')
python练习 根据日志中的ip和url排序的更多相关文章
- Python统计日志中每个IP出现次数
介绍了Python统计日志中每个IP出现次数的方法,实例分析了Python基于正则表达式解析日志文件的相关技巧,需要的朋友可以参考下 本脚本可用于多种日志类型 #-*- coding:utf-8 -* ...
- 配置日志中显示IP
package com.demo.conf; import ch.qos.logback.classic.pattern.ClassicConverter; import ch.qos.logback ...
- logresolve - 解析Apache日志中的IP地址为主机名
logresolve是一个解析Apache访问日志中IP地址的后处理程序. 为了使对名称服务器的影响降到最低,logresolve拥有极为自主的内部散列表缓存, 使每个IP值仅仅在第一次从日志文件中读 ...
- 使用Python 统计nginx日志前十ip访问量并以柱状图显示
脚本内容: import matplotlib.pyplot as plt # nginx_file = '10.6.11.91_access.log-2018-12-27' ip = {} #筛选n ...
- How To:分析ORACLE监听日志中的IP信息
有时候需要分析出ORACLE日志监听中的IP信息,分享一个组合命令,Linux的shell下运行正常. grep "HOST=.*establish.*\* 0" listener ...
- Python习题-统计日志中访问次数超过限制的IP
#1.1分钟之内ip访问次数超过200次的,就给他的ip加入黑名单#需求分析: #1.读日志,1分钟读一次 #2.获取这1分钟之内所有访问的ip #3.判断ip出现的次数,如果出现200次,那么就加入 ...
- python在json文件中提取IP和域名
# qianxiao996精心制作 #博客地址:https://blog.csdn.net/qq_36374896 import re def openjson(path): f = open(pat ...
- python先序、中序、后序排序
#encoding=utf-8 class Tree(): def __init__(self,leftjd=0,rightjd=0,data=0): self.leftjd = leftjd sel ...
- Excel中针对IP地址的排序方法
新建一个辅助排序列,用辅助列来扩展,辅助列公式如下: =TRIM(TEXT(LEFT(SUBSTITUTE(A1,".",REPT(" ",99)),100), ...
随机推荐
- web app页面要求
代码: <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum- ...
- 检测到有潜在危险的 Request.Form
今天在做一个.net的新闻发布器的时候. 遇到这样的一个问,在html编辑器里面加入图片提交的时候 就报一个 从客户端(content1="<img src="/web/ne ...
- Seconds_Behind_Master
http://blog.chinaunix.net/uid-28212952-id-3494560.html 今天同事遇到一个故障,xtrabackup备份中flush tables with rea ...
- Keeplived 详解
http://www.cnblogs.com/pricks/p/3822232.html
- UNIX基础知识之信号
本篇博文内容摘自<UNIX环境高级编程>(第二版),仅作个人学习记录所用.关于本书可参考:http://www.apuebook.com/. 信号(signal)是通知进程已发生某种情况的 ...
- Spring 中JCA CCI分析--转载
转载地址:http://blog.csdn.net/a154832918/article/details/6790612 J2EE提供JCA(Java Connector Architecture)规 ...
- Getting Started with Zend Framework MVC Applications
Getting Started with Zend Framework MVC Applications This tutorial is intended to give an introducti ...
- launch failed.Binary not found in Linux/Ubuntu解决方案
Linux下出现launch failed.Binary not found的解决方案: 首先当你把网上关于mingw的解决方案都看晕了的时候,告诉你,别看关于mingw的了.Linux下不用ming ...
- STL之heap
STL的堆操作 STL里面的堆操作一般用到的只有4个:make_heap();.pop_heap();.push_heap();.sort_heap(); 他们的头文件函数是#include < ...
- 用DAEMON TOOLS打开rational ross 的bin文件并安装过程梳理
最近要开始准备毕业设计了,学习熟悉了一些UML用例图.类图之类的,开始准备用自家PC电脑画图的时候发现Rational Ross没安装. 本以为简单,却碰上bin文件.琢磨好久,终于把Ross安上了. ...