场景:
服务器被搞了,挂了很多暗链,网马,手动清除了后不到一天又生产好多,由于web程序有漏洞,已经重新开发了,所以决定写个脚本坚守2个月,然后等新网站上线。综合黑客动作的特点生成接近300M的html 广告 页面,顾写个脚本监控web目录大小,源程序是186M ,所以我监控190M到300M之间生成的大小的时间,然后去日志查找什么时间来入侵的。 源html的生产时间已经被黑客修改了 无法用来参考。
#coding:utf-8
import os
import time
from os.path import join, getsize
class MyApp:
    dirbase=r‘c:\pyscript‘
    wtxt=r‘c:\pyscript\ip.txt‘
    def _init_(self,name):
        self.name=name
        self.wtxt=wtxt
        self.dirbase=dirbase
    def getdirsize(self,dir):
        size = 0L
        for root, dirs, files in os.walk(dir):
            size += sum([getsize(join(root, name)) for name in files])
        return size
    def wfile(self,xt):
        f = open(xt,‘a‘)
        f.write(‘The Time is %s ‘ %(time.strftime("%Y/%m/%d/-%H:%M:%S"))+‘\n‘)
        f.close()
if __name__==‘__main__‘:
    p = MyApp()
    while True:
        filesize = p.getdirsize(p.dirbase)
        time.sleep(2)
        if filesize >= 199229440 and filesize <= 262144000:
            p.wfile(p.wtxt)
            continue
        else:
            pass
 
本文出自 “把爱投资给希望” 博客,请务必保留此出处http://zhyuxuan.blog.51cto.com/2209663/1386089
python监控web扩张时间脚本,布布扣,bubuko.com
python监控web扩张时间脚本
原文:http://zhyuxuan.blog.51cto.com/2209663/1386089