1 个不稳定版本

0.1.5 2024年1月13日

#4 in #clam-av

Download history 27/week @ 2024-04-08 24/week @ 2024-04-15 30/week @ 2024-04-22 24/week @ 2024-04-29 29/week @ 2024-05-06 40/week @ 2024-05-13 46/week @ 2024-05-20 24/week @ 2024-05-27 33/week @ 2024-06-03 43/week @ 2024-06-10 13/week @ 2024-06-17 65/week @ 2024-06-24 150/week @ 2024-07-01 154/week @ 2024-07-08 156/week @ 2024-07-15 164/week @ 2024-07-22

642 每月下载量

MIT 许可证

7KB
112

Rust ClamAV 客户端

一个简单的 ClamAV 客户端,用于将文件流式传输到 clamd 进行病毒扫描。

请注意:函数 ping_socketscan_socket 只在 Unix 平台上可用。

安装

将此添加到您的 Cargo.toml

[dependencies]
clamav-client = "0.1.3"

用法

通过ping服务器以获取响应来确保 ClamD正在运行

let clamd_host_address = "localhost:3310";

let clamd_available = match clamav_client::ping_tcp(clamd_host_address) {
    Ok(ping_response) => ping_response == b"PONG\0",
    Err(_) => false,
};

if !clamd_available {
    println!("Cannot ping clamd at {}", clamd_host_address);
    return;
}

扫描文件以进行检测

let file_path = "virus.txt";
let scan_response = clamav_client::scan_tcp(file_path, clamd_host_address, None).unwrap();
let file_clean = clamav_client::clean(&scan_response).unwrap();
if file_clean {
    println!("No virus found in {}", file_path);
} else {
    println!("The file {} is infected!", file_path);
}

从内存中扫描缓冲区

let buffer = "X5O!P%@AP[4\\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*"
    .bytes()
    .collect::<Vec<u8>>();

let scan_response = clamav_client::scan_buffer_tcp(buffer, clamd_host_address, None).unwrap();
let file_clean = clamav_client::clean(&scan_response).unwrap();
assert!(!file_clean);

无运行时依赖