python实现集中式的病毒扫描功能详解

作者:cakincqm 时间:2022-03-04 03:16:00 

本文实例讲述了python实现集中式的病毒扫描功能。分享给大家供大家参考,具体如下:

一 点睛

本次实践实现了一个集中式的病毒扫描管理,可以针对不同业务环境定制扫描策略,比如扫描对象、描述模式、扫描路径、调度频率等。案例实现的架构图如下,首先业务服务器开启clamd服务(监听3310端口),管理服务器启用多线程对指定的服务集群进行扫描,扫描模式、扫描路径会传递到clamd,最后返回扫描结果给管理服务器端。

 python实现集中式的病毒扫描功能详解

本次实战通过ClamdNetworkSocket()方法实现与业务服务器建立扫描socket连接,再通过启动不同扫描方式实施病毒扫描并返回结果。

二 代码


#!/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):
   """多进程run方法"""
   try:
     cd = pyclamd.ClamdNetworkSocket(self.IP,3310)
     if cd.ping():
       self.connstr=self.IP+" connection [OK]"
       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.0.120']
scantype="multiscan_file"
scanfile="/data"
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 无病毒的情况下,扫描结果

E:\Python\python_auto_maintain\venv\Scripts\python.exe E:/Python/python_auto_maintain/4_1_2.py
192.168.0.120 connection [OK]
None

2 有病毒的情况下,扫描结果

2.1 制作病毒测试文件

X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*

2.2 扫描结果

E:\Python\python_auto_maintain\venv\Scripts\python.exe E:/Python/python_auto_maintain/4_1_2.py
192.168.0.120 connection [OK]
{u'/data/EICAR': ('FOUND', 'Eicar-Test-Signature')}

希望本文所述对大家Python程序设计有所帮助。

来源:https://blog.csdn.net/chengqiuming/article/details/87900489

标签:python,病毒扫描
0
投稿

猜你喜欢

  • Python几种常见算法汇总

    2023-05-15 21:11:41
  • CSS 表格元素内容的定位 0

    2008-08-01 17:31:00
  • 详解解Django 多对多表关系的三种创建方式

    2021-03-13 04:59:16
  • DedeCMS 5.7 sp1远程文件包含漏洞(CVE-2015-4553)

    2022-05-31 17:37:05
  • Python实现压缩文件夹与解压缩zip文件的方法

    2023-07-31 20:43:09
  • python 实现汉诺塔游戏

    2021-06-28 10:47:51
  • 在Golang中使用Redis的方法示例

    2024-04-28 09:16:01
  • 怎么用Python识别手势数字

    2021-11-14 16:35:35
  • 在Linux中通过Python脚本访问mdb数据库的方法

    2023-12-18 16:23:14
  • MySQL数据库基于sysbench实现OLTP基准测试

    2024-01-28 11:07:14
  • Python获取Linux系统下的本机IP地址代码分享

    2021-07-23 00:26:22
  • Bootstrap3制作自己的导航栏

    2023-08-23 02:13:08
  • 网站防止采集方法全攻略

    2007-09-05 19:57:00
  • Python爬虫基于lxml解决数据编码乱码问题

    2021-09-11 23:48:44
  • python实现机器人卡牌

    2023-05-29 17:27:38
  • Yolov5(v5.0)+pyqt5界面设计图文教程

    2023-01-30 03:30:16
  • win10下mysql 8.0.12 安装及环境变量配置教程

    2024-01-19 22:34:17
  • ES6记录异步函数的执行时间详解

    2024-04-10 16:18:56
  • Bootstrap框架的学习教程详解(二)

    2024-06-05 09:28:56
  • 详解python环境安装selenium和手动下载安装selenium的方法

    2023-10-05 18:07:07
  • asp之家 网络编程 m.aspxhome.com