socks: h12.io/socks Index | Files

package socks

import "h12.io/socks"

Package socks implements a SOCKS (SOCKS4, SOCKS4A and SOCKS5) proxy client.

A complete example using this package:

package main

import (
	"h12.io/socks"
	"fmt"
	"net/http"
	"io/ioutil"
)

func main() {
	dialSocksProxy := socks.Dial("socks5://127.0.0.1:1080?timeout=5s")
	tr := &http.Transport{Dial: dialSocksProxy}
	httpClient := &http.Client{Transport: tr}

	bodyText, err := TestHttpsGet(httpClient, "https://h12.io/about")
	if err != nil {
		fmt.Println(err.Error())
	}
	fmt.Print(bodyText)
}

func TestHttpsGet(c *http.Client, url string) (bodyText string, err error) {
	resp, err := c.Get(url)
	if err != nil { return }
	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil { return }
	bodyText = string(body)
	return
}

Index

Package Files

net.go parse.go socks.go socks4.go socks5.go

Constants

const (
    SOCKS4 = iota
    SOCKS4A
    SOCKS5
)

Constants to choose which version of SOCKS protocol to use.

func Dial Uses

func Dial(proxyURI string) func(string, string) (net.Conn, error)

Dial returns the dial function to be used in http.Transport object. Argument proxyURI should be in the format: "socks5://user:password@127.0.0.1:1080?timeout=5s". The protocol could be socks5, socks4 and socks4a.

func DialSocksProxy Uses

func DialSocksProxy(socksType int, proxy string) func(string, string) (net.Conn, error)

DialSocksProxy returns the dial function to be used in http.Transport object. Argument socksType should be one of SOCKS4, SOCKS4A and SOCKS5. Argument proxy should be in this format "127.0.0.1:1080".

Package socks imports 7 packages (graph) and is imported by 10 packages. Updated 2020-06-23. Refresh now. Tools for package owners.