#socks5 #proxy #server-client #proxy-server #tokio #async

socks5-proxy

socks5-proxy is a socks5 library based on tokio offering both server and client functions

2 releases

0.1.1 Apr 20, 2021
0.1.0 Apr 19, 2021

#17 in #socks5

22 downloads per month

MIT OR Apache-2.0 OR GPL-3.0-or-later

19KB
490 lines

socks5-proxy

socks5-proxy is a socks5 library based on tokio offering both server and client functions.

Usage

Add this to your Cargo.toml dependency

socks5-proxy = "0.1"
tokio = { version = "1", features = ["full"] }
anyhow = "1.0"

Server

use anyhow::Result;
use socks5_proxy::server;

#[tokio::main]
async fn main() -> Result<()> {
    let s = server::new("127.0.0.1:8080".parse()?, None)?;
    s.run().await?;

    Ok(())
}

Client

use anyhow::Result;
use socks5_proxy::{client, Addr};
use tokio::io::{AsyncReadExt, AsyncWriteExt};

#[tokio::main]
async fn main() -> Result<()> {
    let mut client = client::new(
        "localhost:1080",
        &Addr::HostnamePort("www.google.com:80".into()),
        None,
    )
    .await?;

    client.write_all(b"GET / HTTP/1.0\r\n\r\n").await?;
    let mut buffer = Vec::new();
    client.read_to_end(&mut buffer).await?;
    println!("{}", String::from_utf8_lossy(&buffer));

    Ok(())
}

Improvement

All kinds of issues and PRs are welcome!

Dependencies

~3–10MB
~77K SLoC