A Java client for interacting with a ClamAV antivirus server. This client allows you to send commands to the ClamAV server, check its status, and scan files or streams for viruses.
- Connect to a ClamAV server via TCP socket.
- Send commands to check server status and retrieve the version.
- Scan files and byte arrays for viruses.
To use this library, you can clone the repository or include it in your project.
- Java 11 or higher
If you're using Maven, include the following dependency in your pom.xml
:
<dependency>
<groupId>io.github.dawidgorecki</groupId>
<artifactId>clamav-client</artifactId>
<version>1.0.0</version>
</dependency>
To create a client, instantiate the ClamAVClient with the ClamAV server's host and port:
ClamAVClient client = new ClamAVClient("localhost", 3310);
To check if the server is reachable, use the ping() method:
if (client.ping()) {
System.out.println("ClamAV server is reachable!");
} else {
System.out.println("ClamAV server is not reachable.");
}
To retrieve the version of the ClamAV server:
String version = client.getVersion();
System.out.println("ClamAV Version: " + version);
To scan a file for viruses:
File fileToScan = new File("path/to/file.txt");
ScanResult result = client.scan(fileToScan);
To scan a byte array:
byte[] eicar = "X5O!P%@AP[4\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*"
.getBytes(StandardCharsets.US_ASCII);
ScanResult result = client.scan(eicar);
This project is licensed under the MIT License - see the LICENSE file for details.