Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/h12w/socks
A SOCKS (SOCKS4, SOCKS4A and SOCKS5) Proxy Package for Go
https://github.com/h12w/socks
go golang golang-package socks socks4a socks5
Last synced: 4 days ago
JSON representation
A SOCKS (SOCKS4, SOCKS4A and SOCKS5) Proxy Package for Go
- Host: GitHub
- URL: https://github.com/h12w/socks
- Owner: h12w
- License: bsd-2-clause
- Created: 2012-07-31T09:10:22.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2022-10-17T09:28:32.000Z (about 2 years ago)
- Last Synced: 2024-10-18T08:34:44.477Z (25 days ago)
- Topics: go, golang, golang-package, socks, socks4a, socks5
- Language: Go
- Homepage:
- Size: 38.1 KB
- Stars: 505
- Watchers: 27
- Forks: 106
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
SOCKS
=====[![GoDoc](https://godoc.org/h12.io/socks?status.svg)](https://godoc.org/h12.io/socks)
A SOCKS is a SOCKS4, SOCKS4A and SOCKS5 proxy package for Go.
The package provides `socks.Dial` which returns a TCP dialing function from a socks proxy connection string. The returned dialing function can then be used to establish a TCP connection via the socks proxy or be used to initialize `http.Transport` for an HTTP connection.
## Quick Start
### Get the packagego 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}### User/password authentication
dialSocksProxy := socks.Dial("socks5://user:[email protected]:1080?timeout=5s")
## Example
```go
package mainimport (
"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))
}
```