• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

spec/H03-May-2022-

.gitignoreH A D09-Dec-2020252

LICENSEH A D09-Dec-20201.3 KiB

README.mdH A D09-Dec-20201.1 KiB

go.modH A D09-Dec-2020166

go.sumH A D09-Dec-2020452

net.goH A D09-Dec-20201.3 KiB

parse.goH A D09-Dec-20201.1 KiB

parse_test.goH A D09-Dec-2020840

socks.goH A D09-Dec-20202.4 KiB

socks4.goH A D09-Dec-20201.8 KiB

socks5.goH A D09-Dec-20202.4 KiB

socks5_test.goH A D09-Dec-20202.7 KiB

README.md

1SOCKS
2=====
3
4[![GoDoc](https://godoc.org/h12.io/socks?status.svg)](https://godoc.org/h12.io/socks)
5
6SOCKS is a SOCKS4, SOCKS4A and SOCKS5 proxy package for Go.
7
8## Quick Start
9### Get the package
10
11    go get -u "h12.io/socks"
12
13### Import the package
14
15    import "h12.io/socks"
16
17### Create a SOCKS proxy dialling function
18
19    dialSocksProxy := socks.Dial("socks5://127.0.0.1:1080?timeout=5s")
20    tr := &http.Transport{Dial: dialSocksProxy}
21    httpClient := &http.Client{Transport: tr}
22
23### User/password authentication
24
25    dialSocksProxy := socks.Dial("socks5://user:password@127.0.0.1:1080?timeout=5s")
26
27## Example
28
29```go
30package main
31
32import (
33	"fmt"
34	"io/ioutil"
35	"log"
36	"net/http"
37
38	"h12.io/socks"
39)
40
41func main() {
42	dialSocksProxy := socks.Dial("socks5://127.0.0.1:1080?timeout=5s")
43	tr := &http.Transport{Dial: dialSocksProxy}
44	httpClient := &http.Client{Transport: tr}
45	resp, err := httpClient.Get("http://www.google.com")
46	if err != nil {
47		log.Fatal(err)
48	}
49	defer resp.Body.Close()
50	if resp.StatusCode != http.StatusOK {
51		log.Fatal(resp.StatusCode)
52	}
53	buf, err := ioutil.ReadAll(resp.Body)
54	if err != nil {
55		log.Fatal(err)
56	}
57	fmt.Println(string(buf))
58}
59```
60