1 个不稳定版本
0.1.5 | 2024年1月13日 |
---|
#4 in #clam-av
642 每月下载量
7KB
112 行
Rust ClamAV 客户端
一个简单的 ClamAV 客户端,用于将文件流式传输到 clamd 进行病毒扫描。
请注意:函数 ping_socket
和 scan_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);