zoukankan      html  css  js  c++  java
  • python统计nginx脚本信息

     1 #!/usr/bin/env python
     2 # -*- coding: utf-8 -*-
     3 import urllib2
     4 import json
     5 import subprocess
     6 import threading
     7 
     8 #统计10个最频繁访问的ip
     9 ip_raw = subprocess.Popen("cut -d ' ' -f1 host.access.log.* | sort | uniq -c | sort -rn | head -n 10 | awk '{print $2}'",shell=True,stdout=subprocess.PIPE)
    10 iplist = ip_raw.stdout.readlines()
    11 
    12 #淘宝ip库接口
    13 url = "http://ip.taobao.com/service/getIpInfo.php?ip="
    14 
    15 class regionip(threading.Thread):
    16     def __init__(self):
    17         threading.Thread.__init__(self,ip)
    18         self.ip = ip
    19     def run(self):
    20         try:
    21             data = urllib2.urlopen(url + ip,timeout=1).read()
    22             datadict=json.loads(data)
    23             if  datadict["code"] == 0:
    24                 print "%s %s %s %s %s " % (datadict['data']['ip'],datadict["data"]["country"],datadict["data"]["region"],datadict["data"]["city"],datadict["data"]["isp"])
    25         except Exception,e:
    26             print "%s	%s" % (ip,e)
    27 
    28 if __name__=="__main__":
    29     for ip in iplist:
    30         t = regionip(ip)
    31         t.start()
    32         t.join()
  • 相关阅读:
    es6之Promise
    es6之Proxy,Reflect
    js之对象
    Set,Map与Array,Object对比
    es6之数据结构 set,WeakSet,mapWeakMap
    es6之Symbol
    flex布局
    盒子模型,top和margin-top
    POJ1274-The Perfect Stall
    Codeforces 671D. Roads in Yusland 题解
  • 原文地址:https://www.cnblogs.com/metasequoia/p/3754620.html
Copyright © 2011-2022 走看看