linux環境下的python安全掃瞄工具編寫

2021-09-05 10:55:56 字數 1591 閱讀 3935

本次是使用的python自動化裡面的pyclam庫,這個庫是在linux環境裡面專門用來做安全掃瞄,此文只是將模組的基本用法進行描述。

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.constr = ""

self.scanresult = ""

def run(self):

try:

cd = pyclamd.clamdnetworksocket(self.ip,3310)

if cd.ping(): #檢查ip的連通性

self.connstr = self.ip + "connection [ok]"

cd.reload() #過載病毒特徵庫

if self.scan_type == "contsan_file": #對三種掃瞄模式進行定義

self.scanresult = "\n".format(cd.contsan_file(self.file))

elif self.scan_type == "multiscan_file":

self.scanresult = "\n".format(cd.multiscan_file(self.file))

elif self.scan_type == "scan_file":

self.scanresult = "\n".format(cd.scan_file(self.file))

else:

self.connstr = self.ip+"ping error,exit"

return

except exception as e:

self.connstr = self.ip + " "+str(e)

ips = ['192.168.1.21','192.168.1.22']

scantype="multiscan_file"

scanfile ="/data/www"

i=1threadnum = 2

scanlist =

for ip in ips:

currp = scan(ip,scantype,scanfile)

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

Linux下Python環境搭建

linux 下python環境搭建 系統環境 os oracle linux enterprise 5.6 python 位址 版本 python 2.7.3.tgz setuptools 版本 setuptools 0.6c11.tar.gz md5 wget 2.安裝python 檢視系統自帶的...

Linux下搭建Python環境

一 環境 1 作業系統 centos release 6.8 final 2 預安裝環境 python 2.7 二 安裝python 系統自帶的有python環境,首先需要確定當前的版本,因為一些依賴關係,不能直接進行刪除解除安裝操作,這樣有可能會導致其他的依賴關係出現問題 1 檢視當前的pytho...

linux 下 python 環境搭建

一 一般情況下,linux 都會預裝 python 了,但是這個預裝的 python 版本一般都非常低,很多 python 的新特性都沒有,必須重新安裝新一點的版本,從下邊的截圖,可以看到我的 linux 下,預裝 python 的版本非常低,古老的 python 2.6.4rc2 r264rc2 ...