3 releases

new 0.4.0 Feb 20, 2025
0.4.0-rc.1 Feb 12, 2025
0.4.0-rc.0 Feb 10, 2025

#108 in HTTP client

Download history 75/week @ 2025-02-04 175/week @ 2025-02-11

250 downloads per month

MIT/Apache

69KB
1.5K SLoC

socks2

Crates.io Version docs.rs Crates.io MSRV

SOCKS proxy support for Rust.

A fork of sfackler/rust-socks.

See changes.

Using

cargo add socks2

[dependencies]
socks2 = "0.4"

Features

client

[dependencies]
socks2 = { version = "0.4", default-features = false, features = ["client"] }
use socks2::Socks4Stream;
use socks2::Socks5Stream;
use std::io::Write;

let mut connection = Socks4Stream::connect(PROXY, &TARGET, "userid", None).unwrap();
let buf = [126_u8; 50]
connection.write(&buf);

let mut connection = Socks5Stream::connect(PROXY, &TARGET, None).unwrap();
let buf = [126_u8; 50]
connection.write(&buf);

bind

[dependencies]
socks2 = { version = "0.4", default-features = false, features = ["bind"] }
use socks2::Socks4Listener;
use socks2::Socks5Listener;

let mut connection = Socks4Listener::bind(PROXY, &TARGET, "userid", None)
    .unwrap()
    .accept();

let mut connection = Socks5Listener::bind(PROXY, &TARGET, None)
    .unwrap()
    .accept();

udp

[dependencies]
socks2 = { version = "0.4", default-features = false, features = ["udp"] }
use socks2::Socks5Datagram;
use std::io::Write;

let mut connection = Socks5Datagram::bind(PROXY, &TARGET, None).unwrap();
let buf = [126_u8; 50]
connection.send_to(&buf, &OTHER_ADDR);

Versioning

socks2 follows Major Zero Semver. The major version is always zero. Every minor version contains breaking changes. Every patch version will be backwards compatible.

Alpha, Betas, and Release Candidates may contain breaking changes between any version.

Dependencies

~0–7.5MB
~53K SLoC