A SOCKS (SOCKS4, SOCKS4A and SOCKS5) Proxy Package for Go (fork)
Go to file
2019-02-09 11:11:00 +00:00
spec Add spec of SOCKS protocols. 2012-08-01 15:39:46 +08:00
.gitignore Initial commit 2012-07-31 02:10:22 -07:00
go.mod Support Go Modules 2018-12-18 11:18:56 -06:00
LICENSE Add the license file. 2012-08-01 10:14:43 +08:00
README.md new Dial function; support timeout 2019-02-09 11:11:00 +00:00
socks_test.go new Dial function; support timeout 2019-02-09 11:11:00 +00:00
socks.go new Dial function; support timeout 2019-02-09 11:11:00 +00:00

SOCKS

GoDoc

SOCKS is a SOCKS4, SOCKS4A and SOCKS5 proxy package for Go.

Quick Start

Get the package

go get -u "h12.io/socks"

Import the package

import "h12.io/socks"

Create a SOCKS proxy dialing function

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

Example

package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"

	"h12.io/socks"
)

func main() {
	dialSocksProxy := socks.Dial("socks5://127.0.0.1:1080?timeout=5s")
	tr := &http.Transport{Dial: dialSocksProxy}
	httpClient := &http.Client{Transport: tr}
	resp, err := httpClient.Get("http://www.google.com")
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()
	if resp.StatusCode != http.StatusOK {
		log.Fatal(resp.StatusCode)
	}
	buf, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(string(buf))
}