2014-01-21 12:53:06 +00:00
|
|
|
SOCKS
|
|
|
|
=====
|
2012-07-31 09:10:22 +00:00
|
|
|
|
2018-05-05 16:20:55 +00:00
|
|
|
[![GoDoc](https://godoc.org/h12.io/socks?status.svg)](https://godoc.org/h12.io/socks)
|
2012-08-01 03:46:34 +00:00
|
|
|
|
2014-12-19 14:06:56 +00:00
|
|
|
SOCKS is a SOCKS4, SOCKS4A and SOCKS5 proxy package for Go.
|
2012-08-01 03:59:06 +00:00
|
|
|
|
2014-12-19 14:06:56 +00:00
|
|
|
## Quick Start
|
|
|
|
### Get the package
|
2012-08-01 03:59:06 +00:00
|
|
|
|
2018-05-05 16:20:55 +00:00
|
|
|
go get -u "h12.io/socks"
|
2012-08-01 03:59:06 +00:00
|
|
|
|
2014-12-19 14:06:56 +00:00
|
|
|
### Import the package
|
2012-08-01 03:59:06 +00:00
|
|
|
|
2018-05-05 16:20:55 +00:00
|
|
|
import "h12.io/socks"
|
2014-12-19 14:06:56 +00:00
|
|
|
|
|
|
|
### Create a SOCKS proxy dialing function
|
2012-08-01 03:48:26 +00:00
|
|
|
|
2019-02-09 11:11:00 +00:00
|
|
|
dialSocksProxy := socks.Dial("socks5://127.0.0.1:1080?timeout=5s")
|
2012-08-01 03:46:34 +00:00
|
|
|
tr := &http.Transport{Dial: dialSocksProxy}
|
|
|
|
httpClient := &http.Client{Transport: tr}
|
|
|
|
|
2016-06-17 00:04:41 +00:00
|
|
|
## Example
|
|
|
|
|
|
|
|
```go
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
|
2018-05-05 16:20:55 +00:00
|
|
|
"h12.io/socks"
|
2016-06-17 00:04:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2019-02-09 11:11:00 +00:00
|
|
|
dialSocksProxy := socks.Dial("socks5://127.0.0.1:1080?timeout=5s")
|
2016-06-17 00:04:41 +00:00
|
|
|
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))
|
|
|
|
}
|
|
|
|
```
|