async_proxy/clients.rs
1/// Module contains implementations
2/// of the proxification protocol Socks4
3/// and utilities related to the protocol
4///
5/// # Example
6///
7/// ```
8/// use async_proxy::clients::socks4::no_ident::Socks4NoIdent;
9/// use async_proxy::general::ConnectionTimeouts;
10/// use async_proxy::proxy::ProxyConstructor;
11/// use tokio::net::TcpStream;
12/// use std::net::{SocketAddr, SocketAddrV4};
13/// use std::time::Duration;
14/// use std::process::exit;
15///
16/// #[tokio::main]
17/// async fn main() {
18/// // The address of the proxy server that
19/// // will be used to connect through.
20/// // (We used a random proxy from `https://hidemy.name/en/proxy-list/`)
21/// let proxy_addr: SocketAddr = "104.248.63.15:30588".parse().unwrap();
22///
23/// // The address of the destination service
24/// // that we will be connecting to through proxy.
25/// // (We used a tcp echo server from `http://tcpbin.org/`)
26/// let dest_addr: SocketAddrV4 = "52.20.16.20:30000".parse().unwrap();
27///
28/// // Setting up timeouts
29/// let timeouts = ConnectionTimeouts::new(
30/// // Connecting timeout
31/// Duration::from_secs(8),
32/// // Write timeout
33/// Duration::from_secs(8),
34/// // Read timeout
35/// Duration::from_secs(8)
36/// );
37///
38/// // Creating the socks4 constructor,
39/// // using which we will establish a connection
40/// // through proxy
41/// let socks4_proxy = Socks4NoIdent::new(dest_addr, timeouts);
42///
43/// // Connecting to the stream and getting the readable and
44/// // writable stream, or terminating the script if it is
45/// // unable to connect
46/// let stream = TcpStream::connect(proxy_addr)
47/// .await
48/// .expect("Unable to connect to the proxy server");
49///
50/// // Connecting to the service through proxy
51/// let stream = match socks4_proxy.connect(stream).await {
52/// Ok(stream) => {
53/// // Successfully connected to the service
54/// stream
55/// },
56/// Err(e) => {
57/// // -- handling the error -- //
58/// exit(1);
59/// }
60/// };
61/// }
62/// ```
63pub mod socks4;
64
65/// Module contains implementations
66/// of the proxification protocol Socks5
67/// and utilities related to the protocol
68///
69/// # Example
70///
71/// ```
72/// use async_proxy::clients::socks5::{
73/// Destination, no_auth::TcpNoAuth
74/// };
75/// use async_proxy::general::ConnectionTimeouts;
76/// use async_proxy::proxy::ProxyConstructor;
77/// use tokio::net::TcpStream;
78/// use std::net::{
79/// SocketAddr, Ipv4Addr
80/// };
81/// use std::time::Duration;
82/// use std::process::exit;
83///
84/// #[tokio::main]
85/// async fn main() {
86/// // The address of the proxy server that
87/// // will be used to connect through.
88/// // (We used a random proxy from `https://hidemy.name/en/proxy-list/`)
89/// let proxy_addr: SocketAddr = "72.11.148.222:56533".parse().unwrap();
90///
91/// // Setting up timeouts
92/// let timeouts = ConnectionTimeouts::new(
93/// // Connecting timeout
94/// Duration::from_secs(8),
95/// // Write timeout
96/// Duration::from_secs(8),
97/// // Read timeout
98/// Duration::from_secs(8)
99/// );
100///
101/// // The address of the destination service
102/// // that we will be connecting to through proxy.
103/// // (We used a tcp echo server from `http://tcpbin.org/`)
104/// let dest_ipaddr: Ipv4Addr = Ipv4Addr::new(52, 20, 16, 20);
105///
106/// // The port of the destination service
107/// const DEST_PORT: u16 = 30_000;
108///
109/// // Creating the socks5 constructor,
110/// // using which we will establish a connection
111/// // through proxy
112/// let mut socks5_proxy = TcpNoAuth::new(Destination::Ipv4Addr(dest_ipaddr),
113/// DEST_PORT, timeouts);
114///
115/// // Connecting to the stream and getting the readable and
116/// // writable stream, or terminating the script if it is
117/// // unable to connect
118/// let stream = TcpStream::connect(proxy_addr)
119/// .await
120/// .expect("Unable to connect to the proxy server");
121///
122/// // Connecting to the service through proxy
123/// let stream = match socks5_proxy.connect(stream).await {
124/// Ok(stream) => {
125/// // Successfully connected to the service
126/// stream
127/// },
128/// Err(e) => {
129/// // -- handling error -- //
130/// exit(1);
131/// }
132/// };
133///
134/// // -- using `stream` -- //
135/// }
136/// ```
137
138pub mod socks5;