socks5-async

Crates.iosocks5-async
lib.rssocks5-async
version0.1.4
sourcesrc
created_at2020-08-31 15:41:12.287336
updated_at2020-09-20 05:18:36.666949
descriptionAsynchronous SOCKS5 Proxy server/client written in Rust
homepage
repositoryhttps://github.com/alifarrokh/socks5-async
max_upload_size
id283123
size21,197
Ali Farrokh (alifarrokh)

documentation

README

Asynchronous SOCKS5 Proxy server/client written in Rust

Example

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(())
}

TODO

  • Server
  • Client
  • SOCKS5 Commands
    • CONNECT
    • BIND
    • UDP ASSOCIATE
  • SOCKS5 Authentication Methods
    • NO AUTHENTICATION
    • USERNAME/PASSWORD
Commit count: 24

cargo fmt