7个版本
0.2.5 | 2020年8月8日 |
---|---|
0.2.4 | 2020年8月6日 |
0.2.3 | 2020年7月14日 |
0.1.1 | 2020年7月2日 |
#3 in #异步
每月22次下载
49KB
590 行
async-proxy: 快速代理客户端实现
Async proxy 是一个快速灵活的,同时也是异步实现的代理客户端,采用 Rust 编程语言
入门
在你的 Cargo.toml
文件中添加以下行
async-proxy = "0.2.5"
协议
该库支持以下协议
- SOCKS4(稳定)
- SOCKS5(无认证,稳定)
- HTTP(s)(开发中,WIP)
示例
使用异步代理 Socks4
协议实现,无需在连接中提供 ident
的示例
use async_proxy::clients::socks4::no_ident::Socks4NoIdent;
use async_proxy::general::ConnectionTimeouts;
use async_proxy::proxy::ProxyConstructor;
use tokio::net::TcpStream;
use std::net::{SocketAddr, SocketAddrV4};
use std::time::Duration;
use std::process::exit;
#[tokio::main]
async fn main() {
// The address of the proxy server that
// will be used to connect through.
// (We used a random proxy from `https://hidemy.name/en/proxy-list/`)
let proxy_addr: SocketAddr = "104.248.63.15:30588".parse().unwrap();
// The address of the destination service
// that we will be connecting to through proxy.
// (We used a tcp echo server from `http://tcpbin.org/`)
let dest_addr: SocketAddrV4 = "52.20.16.20:30000".parse().unwrap();
// Setting up timeouts
let timeouts = ConnectionTimeouts::new(
// Connecting timeout
Duration::from_secs(8),
// Write timeout
Duration::from_secs(8),
// Read timeout
Duration::from_secs(8)
);
// Creating the socks4 constructor,
// using which we will establish a connection
// through proxy
let socks4_proxy = Socks4NoIdent::new(dest_addr, timeouts);
// Connecting to the stream and getting the readable and
// writable stream, or terminating the script if it is
// unable to connect
let stream = TcpStream::connect(proxy_addr)
.await
.expect("Unable to connect to the proxy server");
// Connecting to the service through proxy
let stream = match socks4_proxy.connect(stream).await {
Ok(stream) => {
// Successfully connected to the service
stream
},
Err(e) => {
// -- handling the error -- //
exit(1);
}
};
}
更多示例请见这里
依赖
~12MB
~294K SLoC