A SOCKS (SOCKS4, SOCKS4A and SOCKS5) Proxy Package for Go (fork)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kayos@tcp.direct c7602dd7e9
Deps
1 week ago
.github Add CI 4 months ago
spec refactor and support user/password authentication 3 years ago
.gitignore Update go module paths 5 months ago
LICENSE Add the license file. 11 years ago
README.md refactor and support user/password authentication 3 years ago
go.mod Deps 1 week ago
go.sum Deps 1 week ago
net.go Optimizations 4 months ago
parse.go Optimizations 4 months ago
parse_test.go Optimizations 4 months ago
socks.go Optimizations 4 months ago
socks4.go Optimizations 4 months ago
socks5.go Optimizations 4 months ago
socks5_test.go Optimizations 4 months ago

README.md

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