__author__ = 'similarface'
from collections import defaultdict
import glob
ip = r"?P<ip>[\d.]*"
date = r"?P<date>\d+"
month = r"?P<month>\w+"
year = r"?P<year>\d+"
log_time = r"?P<time>\S+"
method = r"?P<method>\S+"
request = r"?P<request>\S+"
status = r"?P<status>\d+"
bodyBytesSent = r"?P<bodyBytesSent>\d+"
refer = r"""?P<refer>
[^\"]*
"""
userAgent=r"""?P<userAgent>
.*
"""
import re import linecache
def readline(path):
return linecache.getlines(path) ipad=0
result=defaultdict(int)
p = re.compile(r"(%s)\ -\ -\ \[(%s)/(%s)/(%s)\:(%s)\ [\S]+\]\ \"(%s)?[\s]?(%s)?.*?\"\ (%s)\ (%s)\ \"(%s)\"\ \"(%s).*?\"" %( ip, date, month, year, log_time, method, request, status, bodyBytesSent, refer, userAgent ), re.VERBOSE) acctype=set()
linuxcount=0
Androidcount=0
shoujidict=defaultdict(int)
for line in open('/data4/access.log','r'):
m = re.findall(p, line)
try:
if len(m)!=0:
#"Mozilla/5.0 (Linux; U; Android 4.4.4; zh-cn; SM-G5108Q Build/KTU84P)
#(Linux; U; Android 4.4.2; zh-cn; HUAWEI MT7-CL00 Build/HuaweiMT7-CL00) AppleWebKit/533.1 (KHTML, like Gecko)Version/4.0 MQQBrowser/5.4 TBS/02544
result[m[0][10]]=result[m[0][10]]+1 try:
content=m[0][10]
begin=content.index('(')
end=content.index(')')
shortcontent=content[begin+1:end]
acctype.add(shortcontent.split(';')[0])
#print(shortcontent)
if 'Linux' in shortcontent:
linuxcount=linuxcount+1
shouji=shortcontent.split(';')[4]
shoujidict[shouji]=shoujidict[shouji]+1
if 'Windows' in shortcontent:
pass
if 'iPad' == shortcontent.split(';')[0]:
ipad=ipad+1 except Exception,e:
pass except Exception,e:
#print(m)
pass fopen=open('/tmp/shouji.txt','w')
for k,v in shoujidict.items():
fopen.writelines(k+'\t'+str(v)+"\n")
fopen.close() print(ipad)

  

最新文章

  1. 50个新的汉化Demo!纯前端 Wijmo 放大招
  2. HDU 3328 Flipper 栈 模拟
  3. 使用Unity3D的50个技巧:Unity3D最佳实践
  4. js实现快速排序(in-place)简述
  5. jsp页面中的代码执行加载顺序介绍
  6. jquery如何删除一个元素后面的所有元素
  7. Erlang入门(四)——错误处理和鲁棒性
  8. 实现android activity之间的跳转
  9. poj 1149 PIGS(最大流经典构图)
  10. smarty 截取字符串,调用php中的方法,foreach循环
  11. 几个获取Windows系统信息的Delphi程序
  12. loadrunner解决浏览器死机问题
  13. C语言:使用结构体和指针函数实现面向对象思想(OO编程)
  14. swift项目初始化并添加忽略文件Swift.ignore
  15. 一个在linxu自动切换ip的脚本
  16. php 获取当前在线用户数量
  17. 54个提高PHP程序运行效率的方法(转载)
  18. 老齐python-基础1
  19. ffmpeg一些filter用法、以及一些功能命令
  20. Arcgis Engine(ae)接口详解(7):地图(map)操作

热门文章

  1. flash压力测试
  2. hdu 3123
  3. MUI 授权
  4. 嵌入式学习_AD学习篇
  5. TortoiseGit安装与配置
  6. JDBC连接属性
  7. JQuery增删改查
  8. 业务对象和BAPI
  9. [SAP ABAP开发技术总结]Form(subroutine)、Function参数传值传址
  10. SQL生成包含年月日的流水号