A SOCKS (SOCKS4, SOCKS4A and SOCKS5) Proxy Package for Go (fork)
Go to file
kayos@tcp.direct c7602dd7e9
Deps
2023-01-25 12:27:44 -08:00
.github Add CI 2022-10-16 02:23:41 -07:00
spec refactor and support user/password authentication 2020-05-23 15:33:47 +01:00
.gitignore Update go module paths 2022-08-28 04:17:53 -07:00
LICENSE Add the license file. 2012-08-01 10:14:43 +08:00
README.md refactor and support user/password authentication 2020-05-23 15:33:47 +01:00
go.mod Deps 2023-01-25 12:27:44 -08:00
go.sum Deps 2023-01-25 12:27:44 -08:00
net.go Optimizations 2022-10-16 02:21:24 -07:00
parse.go Optimizations 2022-10-16 02:21:24 -07:00
parse_test.go Optimizations 2022-10-16 02:21:24 -07:00
socks.go Optimizations 2022-10-16 02:21:24 -07:00
socks4.go Optimizations 2022-10-16 02:21:24 -07:00
socks5.go Optimizations 2022-10-16 02:21:24 -07:00
socks5_test.go Optimizations 2022-10-16 02:21:24 -07: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 dialling function

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

User/password authentication

dialSocksProxy := socks.Dial("socks5://user:password@127.0.0.1:1080?timeout=5s")

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))
}