Crates.io | socks5-async |
lib.rs | socks5-async |
version | 0.1.4 |
source | src |
created_at | 2020-08-31 15:41:12.287336 |
updated_at | 2020-09-20 05:18:36.666949 |
description | Asynchronous SOCKS5 Proxy server/client written in Rust |
homepage | |
repository | https://github.com/alifarrokh/socks5-async |
max_upload_size | |
id | 283123 |
size | 21,197 |
Asynchronous SOCKS5 Proxy server/client written in Rust
The following example sends a simple HTTP
request to google.com
through SOCKS5
proxy server.
use socks5_async::{SocksStream, TargetAddr};
use std::{
boxed::Box,
error::Error,
net::{SocketAddr},
};
use tokio::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
// Enter a valid SOCKS5 server
let proxy_addr: SocketAddr = "127.0.0.1:1080".parse().unwrap();
// Send request to google.com
let target_addr = TargetAddr::Domain((String::from("google.com"), 80));
// Pass Some((String, String)) to authenticate with username & password
let userpass = None;
// Connect to server
let mut stream = SocksStream::connect(proxy_addr, target_addr, userpass).await?;
// Send a simple HTTP request
stream.write(b"GET / HTTP/1.1").await?;
stream.write(&[0x0d, 0x0a, 0x0d, 0x0a]).await?;
// Read response
let mut buf = [0; 256]; // 256 bytes => only read few first headers
stream.read(&mut buf).await.expect("Unable to read the response");
println!("{}", std::str::from_utf8(&buf).unwrap());
Ok(())
}
SOCKS5
Commands
CONNECT
BIND
UDP ASSOCIATE
SOCKS5
Authentication Methods
NO AUTHENTICATION
USERNAME/PASSWORD