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), ...
随机推荐
- Thread+Handler 线程 消息循环(转载)
近来找了一些关于android线程间通信的资料,整理学习了一下,并制作了一个简单的例子. andriod提供了 Handler 和 Looper 来满足线程间的通信.例如一个子线程从网络上下载了一副图 ...
- DWRUtil is not defined
错误:DWRUtil is not defined; 解决方法: 先检查页面中是否正确引入uitl.js <script type="text/javascript" src ...
- leetcode -- Largest Rectangle in Histogram TODO O(N)
Given n non-negative integers representing the histogram's bar height where the width of each bar is ...
- MDI/MDIX接口
转载:http://blog.chinaunix.net/uid-24148050-id-137067.html MDI/MDIX is a type of Ethernet port connect ...
- JavaFX(四)窗口大小自由拉伸
1.问题场景 同样的,隐藏掉窗体的默认标题栏也会导致窗体大小自由拉伸功能的失效. 2.解决思路 判断鼠标在窗体的位置,改变鼠标样式,给窗体组件添加拖拽事件监听器,根据鼠标移动位置改变窗体大小. 3.代 ...
- Android(java)学习笔记69:JDK5之后的Lock锁的概述和使用
1. Lock锁的概述: java.util.concurrent.locks,接口Lock 首先Lock是一个接口,Lock实现提供了比使用synchronized方法 和 同步代码块更为广泛的锁定 ...
- oracle索引、 管理权限和角色
索引 1 单列索引create index 索引名 on 表名(列名): 2复合索引在同一张表上可以有多个索引,但是要求列的组合必须不同.create index 索引名 on 表名(列名1, 列名2 ...
- JavaScript开发之路01(初识Sencha Touch框架)
一.SenchaTouch的hello world实例: Ext.application({ name:'myapp', icon:'images/icon.png', glossOnIcon:fal ...
- rpmdb: BDB0113 错误
解决方法: rpm --rebuilddb yum clean all
- flex数据交互方式 转
Flex数据交互方法- httpservice, webservice, RemoteObject, socket. 写在前面: 使用SOAP Web Service同Flex交互有很多好处,但是它很 ...