14 个版本 (8 个稳定版)
4.0.2 | 2024年2月14日 |
---|---|
4.0.1 | 2023年3月10日 |
4.0.0 | 2022年9月20日 |
3.0.2 | 2022年9月4日 |
0.2.0 | 2019年5月21日 |
#965 in 网络编程
每月21,021次下载
用于 8 crate
8KB
87 行
online
📶 检查您的互联网连接的库

功能
- 同时支持异步和阻塞实现。
- 支持IPv4和IPv6。
工作原理
- 尝试连接到Chrome的 captive portal(使用其域名)。
- 如果失败,则尝试Firefox的。
- 如果都失败,则返回第二个错误以帮助诊断。
安装
该库可在 crates.io 上找到。例如,通过 cargo-edit
cargo add online
异步
online = { version = "4.0.0", default-features = false, features = ["tokio"] }
使用
use online::check;
println!("Online? {}", check(None).is_ok());
println!("Online (timeout)? {}", check(Some(5)).is_ok());
示例
cargo run --example sync
cargo run --features="tokio-runtime" --example tokio
依赖关系
~0–8.5MB
~59K SLoC