python實(shí)現(xiàn)集中式的病毒掃描功能詳解
本文實(shí)例講述了python實(shí)現(xiàn)集中式的病毒掃描功能。分享給大家供大家參考,具體如下:
一 點(diǎn)睛
本次實(shí)踐實(shí)現(xiàn)了一個集中式的病毒掃描管理,可以針對不同業(yè)務(wù)環(huán)境定制掃描策略,比如掃描對象、描述模式、掃描路徑、調(diào)度頻率等。案例實(shí)現(xiàn)的架構(gòu)圖如下,首先業(yè)務(wù)服務(wù)器開啟clamd服務(wù)(監(jiān)聽3310端口),管理服務(wù)器啟用多線程對指定的服務(wù)集群進(jìn)行掃描,掃描模式、掃描路徑會傳遞到clamd,最后返回掃描結(jié)果給管理服務(wù)器端。

本次實(shí)戰(zhàn)通過ClamdNetworkSocket()方法實(shí)現(xiàn)與業(yè)務(wù)服務(wù)器建立掃描socket連接,再通過啟動不同掃描方式實(shí)施病毒掃描并返回結(jié)果。
二 代碼
#!/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):
"""構(gòu)造方法"""
Thread.__init__(self)
self.IP = IP
self.scan_type=scan_type
self.file = file
self.connstr=""
self.scanresult=""
def run(self):
"""多進(jìn)程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
三 結(jié)果
1 無病毒的情況下,掃描結(jié)果
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 有病毒的情況下,掃描結(jié)果
2.1 制作病毒測試文件
X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
2.2 掃描結(jié)果
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')}
更多關(guān)于Python相關(guān)內(nèi)容可查看本站專題:《Python Socket編程技巧總結(jié)》、《Python進(jìn)程與線程操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python入門與進(jìn)階經(jīng)典教程》及《Python文件與目錄操作技巧匯總》
希望本文所述對大家Python程序設(shè)計(jì)有所幫助。
- 十行代碼使用Python寫一個USB病毒
- Python實(shí)現(xiàn)掃描局域網(wǎng)活動ip(掃描在線電腦)
- Python實(shí)現(xiàn)的多線程端口掃描工具分享
- python基礎(chǔ)教程之udp端口掃描
- python局域網(wǎng)ip掃描示例分享
- Python腳本實(shí)現(xiàn)Web漏洞掃描工具
- Python掃描IP段查看指定端口是否開放的方法
- Python端口掃描簡單程序
- python多線程掃描端口示例
- 實(shí)例探究Python以并發(fā)方式編寫高性能端口掃描器的方法
- python實(shí)現(xiàn)上傳樣本到virustotal并查詢掃描信息的方法
- Python實(shí)現(xiàn)簡易端口掃描器代碼實(shí)例
相關(guān)文章
Python3二分查找?guī)旌瘮?shù)bisect(),bisect_left()和bisect_right()的區(qū)別
這篇文章主要介紹了Python3二分查找?guī)旌瘮?shù)bisect(),bisect_left()和bisect_right()的區(qū)別,本文通過示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-03-03
基于Python的EasyGUI學(xué)習(xí)實(shí)踐
這篇文章主要介紹了基于Python的EasyGUI學(xué)習(xí)實(shí)踐,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-05-05
Python將Excel表格按某列拆分為多個sheet實(shí)現(xiàn)過程
這篇文章主要為大家介紹了Python實(shí)現(xiàn)將Excel表格按某列拆分為多個sheet,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05

