A SOCKS (SOCKS4, SOCKS4A and SOCKS5) Proxy Package for Go

Overview

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:[email protected]: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))
}
Comments
  • authentication support

    authentication support

    I found that in a bad network environment, sendReceive lost the packet and did not respond, which caused the "http.Transport" process to permanently block in "Dial". So I set the default timeout for sendReceive.

    In addition, support for authentication has been added.

    help wanted 
    opened by bigemon 4
  • Request stuck at ReadAll

    Request stuck at ReadAll

    For some reason code got freeze on method

    func readAll(conn net.Conn) (resp []byte, err error)
    

    I tested my proxy, and also bunch of others - same result. Here is my code:

    package main
    
    import (
        "h12.me/socks"
        "log"
    )
    
    func main() {
        server := "x.x.x.x:9999"
        proxyServer := "x.x.x.x:8888" // TinyProxy, Socks5
    
        f := socks.DialSocksProxy(socks.SOCKS5, proxyServer)
    
        conn, err := f("tcp", server)
    
        if err != nil {
            log.Println("err", err)
        }
        conn.Write([]byte("Hello")) # This line is never reached
        defer conn.Close()
    }
    

    Any ideas? Thanks.

    opened by firstrow 4
  • Timeout does not work with fasthttp.Client

    Timeout does not work with fasthttp.Client

    Hello, I've faced with an issue when timeout param doesn't work with fasthttp client. Here is my func which i pass as an field Dial to the fasthttp.Client

    func(addr string) (net.Conn, error) {
    			dialer := socks.Dial(proxyAddr + "?timeout=4s")
    			return dialer("tcp", addr)
    		}
    

    and prepare the client:

    fasthttp.Client{
    		Dial: prepareProxy(proxy),
    	}
    

    I must admit that with a valid proxy it works

    opened by Numenorean 2
  • Support Go Modules

    Support Go Modules

    Hello,

    Please consider supporting Go Modules, the new packaging standard that will be adopted fully in Go 1.12. Experimental support is in Go 1.11 and the go.mod file is supported in Go 1.9.7+ and Go 1.10.3+ in a read-only manner for backwards compatibility with all supported versions of Go.

    Because this library has no external dependencies and is still below version 2, the go.mod file is fairly simple. The only other thing that would need to be done is to create a semver compatible tag after this patch is merged (eg. v1.0.1) to allow other things to pin to that version without having to use the special commit-based version string.

    Thank you for your consideration.

    opened by SamWhited 2
  • what does code in directory /root/go/gopath/src/github.com/h12w/socks expects import

    what does code in directory /root/go/gopath/src/github.com/h12w/socks expects import "h12.io/socks" mean?

    hi. [email protected]:~/go/gopath# go get -u -v github.com/h12w/socks github.com/h12w/socks (download) package github.com/h12w/socks: code in directory /root/go/gopath/src/github.com/h12w/socks expects import "h12.io/socks" [email protected]:~/go/gopath#

    how to fix it?

    opened by luckypoem 2
  • go get broken

    go get broken

    [email protected]:~$ go get -u h12.me/socks# cd .; git clone https://h12.me/socks /home/guru/workspace/go/src/h12.me/socks
    Cloning into '/home/guru/workspace/go/src/h12.me/socks'...
    fatal: unable to access 'https://h12.me/socks/': gnutls_handshake() failed: Handshake failed
    package h12.me/socks: exit status 128
    
    opened by gurupras 2
  • Fix for missing returns.

    Fix for missing returns.

    Fix for error index out of bounds.

    panic: runtime error: index out of range

    goroutine 46 [running]: h12.me/socks.dialSocks4(0x0, 0x187f68e0, 0x10, 0x187f6b20, 0x10, 0xb6b91588, 0x1880e080, 0xb6b8c018, 0x1880e188) /root/go/src/h12.me/socks/socks.go:161 +0x982 h12.me/socks.DialSocksProxy.func2(0x8379b4c, 0x3, 0x187f6b20, 0x10, 0x0, 0x0, 0x0, 0x0) /root/go/src/h12.me/socks/socks.go:69 +0x60 net/http.(_Transport).dial(0x187598f0, 0x8379b4c, 0x3, 0x187f6b20, 0x10, 0x0, 0x0, 0x0, 0x0) /usr/lib/go/src/net/http/transport.go:499 +0x68 net/http.(_Transport).dialConn(0x187598f0, 0x0, 0x83b0f20, 0x4, 0x187f6b20, 0x10, 0x0, 0x0, 0x0) /usr/lib/go/src/net/http/transport.go:596 +0x1619 net/http.(_Transport).getConn.func4(0x187598f0, 0x0, 0x83b0f20, 0x4, 0x187f6b20, 0x10, 0x187fc140) /usr/lib/go/src/net/http/transport.go:549 +0x4d created by net/http.(_Transport).getConn /usr/lib/go/src/net/http/transport.go:551 +0x20d

    opened by alekc 2
  • Package import comment and minor README update

    Package import comment and minor README update

    replaces the buggy https://github.com/hailiang/socks/pull/3

    import "magic" comment goes next to the package declaration: package socks // import "h12.me/socks"

    opened by dmitris 2
  • add import comment to avoid aliasing and be clear about the import path

    add import comment to avoid aliasing and be clear about the import path

    import comment as described in https://golang.org/s/go14customimport

    This would be consistent with README.md https://github.com/hailiang/socks#import-the-package declaring that the import path is "h12.me/socks" (and not "github.com/hailiang/socks"). The change will help to avoid confusion regarding under which import path the package should be included and potentially the package being linked under two different import paths (through transitive dependencies, etc.)

    This will break builds of clients still using "github.com/hailiang/socks" but on the other hand will inform them about the canonical import path for the package.

    opened by dmitris 2
  • Prefer ipv4 address when lookup hosts

    Prefer ipv4 address when lookup hosts

    https://github.com/h12w/socks/blob/4d67a7057a35e9e22aba15c7716a673c00e62339/net.go#L46

    func lookupIP(host string) (net.IP, error) {
    	ips, err := net.LookupIP(host)
    	if err != nil {
    		return nil, err
    	}
    	if len(ips) == 0 {
    		return nil, fmt.Errorf("cannot resolve host: %s", host)
    	}
    
    	for _, ip := range ips {
    		ip4 := ip.To4()
    		if len(ip4) != net.IPv4len {
    			continue
    		}
    		return ip4, nil
    	}
    
    	return nil, fmt.Errorf("no ipv4 address found for host: %s", host)
    }
    
    opened by darren 1
  • socks4 do not work

    socks4 do not work

    2020/06/20 13:36:12 Get "https://www.google.com": net/http: Transport.Dial hook returned (nil, nil) 2020/06/20 13:36:55 Get "https://www.google.com": EOF

    Worker proxies, sample code used

    dialSocksProxy := socks.Dial("socks4://45.129.201.209:4145") tr := &http.Transport{Dial: dialSocksProxy} httpClient := &http.Client{Transport: tr} resp, err := httpClient.Get("https://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))

    opened by ghost 1
  • [RFC 1928] Implement UDP Associate

    [RFC 1928] Implement UDP Associate

    https://datatracker.ietf.org/doc/html/rfc1928

    I think it makes sense to implement a UDP association to be able to proxy UDP packets

    If you do not plan to add this feature, I can later add a pull request with my implementation

    enhancement help wanted 
    opened by EnjoyPM 0
Owner
Hǎi-Liàng "Hal" Wáng
Principal Developer in London
Hǎi-Liàng
Inspired by go-socks5,This package provides full functionality of socks5 protocol.

The protocol described here is designed to provide a framework for client-server applications in both the TCP and UDP domains to conveniently and securely use the services of a network firewall.

Zhangliu 68 Sep 27, 2022
Multi-threaded socks proxy checker written in Go!

Soxy - a very fast tool for checking open SOCKS proxies in Golang I was looking for some open socks proxies, and so I needed to test them - but really

pry0cc 45 Sep 6, 2022
SOCKS Protocol Version 5 Library in Go. Full TCP/UDP and IPv4/IPv6 support

socks5 中文 SOCKS Protocol Version 5 Library. Full TCP/UDP and IPv4/IPv6 support. Goals: KISS, less is more, small API, code is like the original protoc

TxThinking 499 Dec 5, 2022
SOCKS5/4/4a validating proxy pool. Water's fine on my machine!

PxndScvm SOCKS5/4/4a validating proxy pool This package is for managing and accessing thousands upon thousands of arbitrary SOCKS proxies. Pipe it a f

null 37 Nov 21, 2022
socks5 proxy server with auto upstream selection

atproxy socks5 proxy server with auto upstream selection installation go install github.com/reusee/atproxy/[email protected] select process for each cli

null 10 Dec 22, 2021
🧮 SOCKS5/4/4a 🌾 validating proxy pool for 🤽 LOLXDsoRANDum connections 🎋

Prox5 SOCKS5/4/4a validating proxy pool This package is for managing and accessing thousands upon thousands of arbitrary SOCKS proxies. It also has a

kayos 37 Nov 21, 2022
A socks5 proxy over quica

A socks5 proxy over quica

null 20 Nov 9, 2022
SOCKS5 proxy for go-gemini

go-gemini-socks5 SOCKS5 proxy for go-gemini. go get github.com/makeworld-the-better-one/go-gemini-socks5 Import as "github.com/makeworld-the-better-o

makeworld 1 Apr 6, 2022
A socks5 server(tcp/udp) written in golang.

socks5-server A socks5 server(tcp/udp) written in golang. Usage Usage of /main: -l string local address (default "127.0.0.1:1080") -p stri

null 32 Nov 20, 2022
Golang 实现的简单 Socks5 代理

Socks5-Proxy 简介:Golang 实现的 Socks5 代理服务端,支持用户名、密码验证。 安装 下载 git clone https://github.com/truda8/Socks5-Proxy.git 构建 go build -o socks5proxy main.go 添加执

Truda 2 Dec 15, 2021
SOCKS5 server in Golang

go-socks5 Provides the socks5 package that implements a SOCKS5 server. SOCKS (Secure Sockets) is used to route traffic between a client and server thr

null 1 Feb 7, 2022
Crimson prober - Asynchronous TCP scanner through SOCKS5 proxies

Crimson Prober v1 Alpha version of Asynchronous TCP scanner through SOCKS5 proxi

karmaz 2 Feb 19, 2022
IP2Proxy Go package allows users to query an IP address to determine if it was being used as open proxy, web proxy, VPN anonymizer and TOR exits.

IP2Proxy Go Package This package allows user to query an IP address if it was being used as VPN anonymizer, open proxies, web proxies, Tor exits, data

IP2Location 11 Sep 15, 2022
An experimental Tor-Proxy serivce written in Go using Go-proxy and Go-libtor.

tor-proxy An experimental standalone tor-proxy service built with Go, using go-proxy, go-libtor and bine. This is a simple replacement to Tor's origin

Narasimha Prasanna HN 35 Nov 9, 2022
Battlesnake-logging-proxy - A little proxy between the internet and your battlesnake

battlesnake-logging-proxy a little proxy between the internet and your battlesna

Penelope Phippen 3 Feb 11, 2022
mt-multiserver-proxy is a reverse proxy designed for linking multiple Minetest servers together

mt-multiserver-proxy mt-multiserver-proxy is a reverse proxy designed for linking multiple Minetest servers together. It is the successor to multiserv

null 16 Nov 17, 2022
A simple tool to convert socket5 proxy protocol to http proxy protocol

Socket5 to HTTP 这是一个超简单的 Socket5 代理转换成 HTTP 代理的小工具。 如何安装? Golang 用户 # Required Go 1.17+ go install github.com/mritd/[email protected] Docker 用户 docker pull m

mritd 7 Sep 7, 2022