About
pyClamd is a python interface to Clamd (Clamav daemon). By using pyClamd, you can
add virus detection capabilities to your python software in an efficient and
easy way.
Instead of pyClamav which uses libclamav, pyClamd may be used by a closed source product.
Download latest
pyclamd.py - 2006-07-16
md5sum is fcdc195401e8c78a0d19ee6b8c23fdcb
CHANGELOG.
top
Installation
- These are generic installation instructions.
-
You need to have clamav with clamd installed.
You also need to have python
installed. Clamd should be accessible either by network or by unix socket.
You just have to copy pyclamd.py in your site-packages directory (for example : /usr/lib/python2.3/site-packages/). Or if you do not want a wide system installation, you can leave pyclamd.py in your application directory.
top
Usage
- From python :
-
Python 2.3.5 (#2, Sep 4 2005, 22:01:42)
[GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyclamd
>>> pyclamd.init_network_socket('localhost', 3310)
>>> print pyclamd.version()
ClamAV 0.88.3/1598/Thu Jul 13 13:38:16 2006
>>> ret = pyclamd.scan_file('/tmp/eicar.com')
>>> print ret
{'/tmp/eicar.com': 'Eicar-Test-Signature'}
>>> ret = pyclamd.scan_file('/tmp/no_virus.txt')
>>> print ret
None
>>> ret = pyclamd.scan_stream(open('/tmp/eicar.com').read())
>>> print ret
{'stream': 'Eicar-Test-Signature FOUND'}
top
Functions
- init_network_socket(host='127.0.0.1', port=3310)
- Init pyclamd to use clamd network socket
- host (string) : clamd server adresse
- port (int) : clamd server port
return : Nothing
May raise :
- TypeError : if host is not a string or port is not an int
- ValueError : if the server can not be pingged
- init_unix_socket(filename='/var/run/clamd')
- Init pyclamd to use clamd unix local socket
- filename (string) : clamd file for local unix socket
return : Nothing
May raise :
- TypeError : if filename is not a string
- ValueError : if filename does not allow to ping the server
- ping()
- Send a PING to the clamav server, which should reply
by a PONG.
return : True if the server replies to PING
May raise :
- ScanError : if the server do not reply by PONG
- version()
- Get Clamscan version
return : (string) clamscan version
May raise :
- ScanError : in case of communication problem
- contscan_file(file)
- Scan a file or directory given by filename
- file (string) : filename or directory (MUST BE ABSOLUTE PATH !)
return either :
- (dict) : {filename1: "virusname", filename2: "virusname"}
- None if no virus found
May raise :
- ScanError : in case of communication problem
- scan_file(file)
- Scan a file or directory given by filename and stop on virus
- file (string) : filename or directory (MUST BE ABSOLUTE PATH !)
return either :
- (dict) : {filename1: "virusname"}
- None if no virus found
May raise :
- ScanError : in case of communication problem
- scan_stream(buffer)
- Scan a buffer
- buffer (string) : buffer to scan
return either :
- (dict) : {filename1: "virusname"}
- None if no virus found
May raise :
- BufferTooLong : if the buffer size exceeds clamd limits
- ScanError : in case of communication problem
- reload()
- Force Clamd to reload signature database
return : (string) "RELOADING"
May raise :
- ScanError : in case of communication problem
- shutdown()
- Force Clamd to shutdown and exit
return : nothing
May raise :
- ScanError : in case of communication problem
top
License
This program is free software; you can redistribute it and/or modify
it under the terms of the
GNU General Public License
as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.