dlzht-socks5

Crates.iodlzht-socks5
lib.rsdlzht-socks5
version0.1.0
sourcesrc
created_at2024-08-19 06:19:13.914892
updated_at2024-08-19 06:19:13.914892
descriptionlibrary for SOCKS5, RFC 1928
homepage
repositoryhttps://github.com/dlzht/dlzht-socks5
max_upload_size
id1343520
size98,883
dlzht (dlzht)

documentation

https://docs.rs/dlzht-socks5

README

This library is an implement of SOCKS5, RFC1928. So far, auth method of NO AUTHENTICATION REQUIRED and USERNAME/PASSWORD is supported, command CONNECT is supported.

Examples

Run server without any authorization

use dlzht_socks5::server::SocksServerBuilder;

#[tokio::main]
async fn main() {
    let server = SocksServerBuilder::new()
        .allow_auth_skip(true)
        .build().unwrap();
    let _ = server.start().await;
}

Run server with password authorization

use dlzht_socks5::server::SocksServerBuilder;

#[tokio::main]
async fn main() {
    let server = SocksServerBuilder::new()
        .credential(b"username", b"password")
        .build().unwrap();
    let _ = server.start().await;
}

Custom validate username/password

Will support soon

Run client without any authorization

use dlzht_socks5::client::SocksClientBuilder;
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};

#[tokio::main]
async fn main() {
    let address = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080));
    let mut client = SocksClientBuilder::new()
        .server_address(address)
        .allow_auth_skip(true)
        .build()
        .unwrap();
    let mut stream = client
        .connect(("127.0.0.1".to_string(), 9000))
        .await
        .unwrap();
}

Run client with password authorization

use dlzht_socks5::client::SocksClientBuilder;
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};

#[tokio::main]
async fn main() {
    let address = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::new(127, 0, 0, 1), 8080));
    let mut client = SocksClientBuilder::new()
        .server_address(address)
        .credential(b"username", b"password")
        .build()
        .unwrap();
    let mut stream = client
        .connect(("127.0.0.1".to_string(), 9000))
        .await
        .unwrap();
}
Commit count: 0

cargo fmt