|
| 1 | +# clamd |
| 2 | + |
| 3 | +`clamd` is a portable Python module to use the ClamAV anti-virus engine on Windows, Linux, MacOSX and other platforms. It requires a running instance of the clamd daemon. |
| 4 | + |
| 5 | +### History |
| 6 | + |
| 7 | +This is a fork of `pyClamd` (v0.2.0) created by Philippe Lagadec and published on [his](http://www.decalage.info/en/python/pyclamd) website, which in turn is a slightly improved version of `pyClamd` (v0.1.1) created by Alexandre Norman and published on [his](http://xael.org/norman/python/pyclamd/) website. |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +Make sure you have installed both `clamav` engine and `clamav-daemon`, for instance, you can install it on Ubuntu by running the following commands: |
| 12 | + |
| 13 | +```bash |
| 14 | +apt-get install clamav-daemon clamav-freshclam clamav-unofficial-sigs |
| 15 | +freshclam # update the database |
| 16 | +systemctl start clamav-daemon |
| 17 | +``` |
| 18 | + |
| 19 | +```bash |
| 20 | +pip install clamd |
| 21 | +``` |
| 22 | + |
| 23 | +## Usage/Examples |
| 24 | + |
| 25 | +To use with a Unix socket: |
| 26 | + |
| 27 | +```python |
| 28 | +>>> import clamd |
| 29 | +>>> cd = clamd.ClamdUnixSocket() |
| 30 | +>>> cd.ping() |
| 31 | +'PONG' |
| 32 | +>>> cd.version() # doctest: +ELLIPSIS |
| 33 | +'ClamAV ... |
| 34 | +>>> cd.reload() |
| 35 | +'RELOADING' |
| 36 | +``` |
| 37 | + |
| 38 | +To scan a file: |
| 39 | + |
| 40 | +```python |
| 41 | +>>> open('/tmp/EICAR','wb').write(clamd.EICAR) |
| 42 | +>>> cd.scan('/tmp/EICAR') |
| 43 | +{'/tmp/EICAR': ('FOUND', 'Eicar-Test-Signature')} |
| 44 | +``` |
| 45 | + |
| 46 | +To scan a stream: |
| 47 | +```python |
| 48 | +>>> from io import BytesIO |
| 49 | +>>> cd.instream(BytesIO(clamd.EICAR)) |
| 50 | +{'stream': ('FOUND', 'Eicar-Test-Signature')} |
| 51 | +``` |
| 52 | +`clamav` daemon runs under `clamav` user and might not be able to scan files owned by other users or root user, in this case you can use `fdscan` function which opens a file and then passes the file descriptor to `clamav` daemon: |
| 53 | + |
| 54 | +```python |
| 55 | +>>> open('/tmp/EICAR','wb').write(clamd.EICAR) |
| 56 | +>>> cd.fdscan('/tmp/EICAR') |
| 57 | +{'/tmp/EICAR': ('FOUND', 'Eicar-Test-Signature')} |
| 58 | +``` |
| 59 | + |
| 60 | +## License |
| 61 | + |
| 62 | +clamd is released as open-source software under the LGPL license. |
0 commit comments