nainai1 发表于 2018-8-10 06:00:04

python 使用ClamAV实现病毒扫描(pyClamad)

#!/usr/bin/env python  
# -*- coding: utf-8 -*-
  

  
import time
  
import pyclamd
  
from threading import Thread
  

  
class Scan(Thread):
  
      def __init__ (self,IP,scan_type,file):
  
                Thread.__init__(self)
  
                self.IP=IP
  
                self.scan_type=scan_type
  
                self.file=file
  
                self.connstr=""
  
                self.scanresult=""
  

  
      def run(self):
  
                try:
  
                        cd=pyclamd.ClamdNetworkSocket(self.IP,3310)
  
                        if cd.ping():
  
                              self.connstr=self.IP+" connection "
  
                              cd.reload()
  
                              if self.scan_type=="contscan_file":
  
                                        self.scanresult="{0}\n".format(cd.contscan_file(self.file))
  
                              elif self.scan_type=="multiscan_file":
  
                                        self.scanresult="{0}\n".format(cd.multiscan_file(self.file))
  
                              elif self.scan_type=="scan_file":
  
                                        self.scanresult="{0}\n".format(cd.scan_file(self.file))
  
                              time.sleep(1)
  
                        else:
  
                              self.connstr=self.IP+" ping error,exit"
  
                              return
  
                except Exception,e:
  
                        self.connstr=self.IP+" "+str(e)
  

  
IPS=['192.168.1.124','192.168.1.116']
  
scantype="multiscan_file"
  
scanfile="/home/python/test"
  
i=1
  

  
threadnum=2
  
scanlist=[]
  

  
for ip in IPS:
  
      currp=Scan(ip,scantype,scanfile)
  
      scanlist.append(currp)
  
      if i%threadnum==0 or i==len(IPS):
  
                for task in scanlist:
  
                        task.start()
  
                for task in scanlist:
  
                        task.join()
  
                        print task.connstr
  
                        print task.scanresult
  
                scanlist=[]
  
      i+=1
页: [1]
查看完整版本: python 使用ClamAV实现病毒扫描(pyClamad)