55个版本 (14个稳定版)

1.1.6 2024年7月23日
1.1.1 2024年5月2日
1.0.6 2024年2月28日
0.3.0-alpha62024年1月23日
0.1.1 2023年8月5日

#80硬件支持

Download history 166/week @ 2024-04-19 140/week @ 2024-04-26 38/week @ 2024-05-03 8/week @ 2024-05-17 7/week @ 2024-05-24 3/week @ 2024-05-31 2/week @ 2024-06-07 1/week @ 2024-06-14 2/week @ 2024-06-21 73/week @ 2024-07-05 140/week @ 2024-07-12 468/week @ 2024-07-19 52/week @ 2024-07-26 3/week @ 2024-08-02

664 每月下载次数

MIT 许可证

6MB
6K SLoC

包含 (APK文件, 7MB) test_files/app-debug.apk

radb_client

简单的Android adb客户端,用于Rust。

crates.io

示例


use radb_client::{*};

pub fn main() {
    let adb = Adb::new().unwrap();
    let device_ip = String::from("192.168.1.128");
    let conn = ConnectionType::try_from_ip(device_ip).unwrap();
    let client = Client::try_from(conn).unwrap();

    match client.connect() {
        Ok(()) => println!("Device connected"),
        Err(err) => println!("Error connecting to device: {:?}", err),
    }
}

使用功能 scanner 也可以扫描所有可用的设备

use std::str::FromStr;
use std::time::{Duration, Instant};

use cidr_utils::cidr::Ipv4Cidr;
use cidr_utils::Ipv4CidrSize;
use crossbeam_channel::unbounded;
use indicatif::{MultiProgress, ProgressBar, ProgressStyle};
use itertools::Either;

use crate::scanner::Scanner;
use crate::test::test::init_log;
use crate::types::Adb;

fn test_scan() {
    let cidr = Ipv4Cidr::from_str("192.168.1.0/24").unwrap();
    let progress_style = ProgressStyle::with_template(
        "{prefix:.cyan.bold/blue.bold}: {elapsed_precise} [{bar:40.cyan/blue}] {percent:.bold}%. {msg} ",
    )
        .unwrap()
        .progress_chars("=> ");

    let multi_progress = MultiProgress::new();
    let progress = multi_progress.add(ProgressBar::new(cidr.size()));
    progress.set_style(progress_style.clone());
    progress.set_prefix("Scanning");

    let (tx, rx) = unbounded();
    let adb = Adb::new().expect("failed to find adb");

    let scanner = Scanner::default()
        .with_debug(false)
        .with_tcp_timeout(Duration::from_millis(200))
        .with_adb_timeout(Duration::from_millis(100));

    let start = Instant::now();
    scanner.scan(&adb, cidr.iter(), tx.clone());

    drop(tx);

    let mut result = Vec::new();
    for either in rx {
        match either {
            Either::Left(addr) => {
                progress.inc(1);
                progress.set_message(format!("{addr}..."));
            }
            Either::Right(client) => {
                if !result.contains(&client) {
                    result.push(client);
                }
            }
        }
    }
    
    progress.finish_with_message(format!("Scanned {} IPs", cidr.size()));

    let elapsed = start.elapsed();

    println!("Time elapsed for scanning is: {:?}ms", elapsed.as_millis());
    println!("Found {:} devices", result.len());

    result.sort_by_key(|k| k.conn);

    for device in result.iter() {
        println!("{device}");
    }
}

依赖

~16–33MB
~542K SLoC