net/proxy
Connecting through an HTTP or SOCKS5 proxy, alone or in a chain.
import net.proxy
A proxy is a middleman that makes the connection on behalf of the program. This package builds the tunnel and gives back an ordinary net/tcp connection, read and written exactly as a direct one is.
Types
Proxy
struct Proxy| Name | Type | Description |
|---|---|---|
kind | int = 0 | The kind; one of the Type constants. |
host | str = "" | The host. |
port | int = 0 | The port. |
username | str = "" | The user name, when one is needed. |
password | str = "" | The password. |
import net.proxy
func main:
a := proxy.NewHTTPProxy("10.0.0.1:3128")
println a.kind == proxy.TypeHTTP, a.host, a.port
b := proxy.NewHTTPProxyAuth("proxy.local:8080", "ali", "secret")
println b.username, b.password
c := proxy.NewSOCKS5Proxy("127.0.0.1:1080")
d := proxy.NewSOCKS5ProxyAuth("socks.local:1080", "u", "p")
println c.kind == proxy.TypeSOCKS5, d.port
mut chain := proxy.NewChain()
proxy.Add(chain, c)
proxy.Add(chain, a)
println chain.items.len()
endChain
struct Chain| Name | Type | Description |
|---|---|---|
items | Vector | The proxies in order. |
The example for this item is shown with the ones above: net-proxy-Proxy.salam
Constants and variables
TypeHTTP
const TypeHTTP: i32 = 0The example for this item is shown with the ones above: net-proxy-Proxy.salam
TypeSOCKS5
const TypeSOCKS5: i32 = 1The example for this item is shown with the ones above: net-proxy-Proxy.salam
Functions
NewHTTPProxy
func NewHTTPProxy(addr: str): Proxyhost:port address.The example for this item is shown with the ones above: net-proxy-Proxy.salam
NewHTTPProxyAuth
func NewHTTPProxyAuth(addr: str, username: str, password: str): ProxyThe example for this item is shown with the ones above: net-proxy-Proxy.salam
NewSOCKS5Proxy
func NewSOCKS5Proxy(addr: str): ProxyThe example for this item is shown with the ones above: net-proxy-Proxy.salam
NewSOCKS5ProxyAuth
func NewSOCKS5ProxyAuth(addr: str, username: str, password: str): ProxyThe example for this item is shown with the ones above: net-proxy-Proxy.salam
Dial
func Dial(p: Proxy, target_host: str, target_port: int): tcp.Connimport net.proxy
import net.tcp
func main:
p := proxy.NewSOCKS5Proxy("127.0.0.1:1080")
conn := proxy.Dial(p, "example.com", 80)
mut chain := proxy.NewChain()
proxy.Add(chain, p)
conn2 := proxy.DialChain(chain, "example.com", 80)
println tcp.ConnOk(conn), tcp.ConnOk(conn2)
endNewChain
func NewChain(): ChainThe example for this item is shown with the ones above: net-proxy-Proxy.salam
Add
func Add(c &: Chain, p: Proxy)The example for this item is shown with the ones above: net-proxy-Proxy.salam
DialChain
func DialChain(c: Chain, target_host: str, target_port: int): tcp.ConnThe example for this item is shown with the ones above: net-proxy-Dial.salam