Code Monkey home page Code Monkey logo

socks's Introduction

SOCKS

GoDoc

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 package

go 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

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

socks's People

Contributors

alekc avatar dmitris avatar dmitry-online avatar h12w avatar samwhited avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

socks's Issues

Prefer ipv4 address when lookup hosts

socks/net.go

Line 46 in 4d67a70

func lookupIP(host string) (net.IP, error) {

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

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.

go get broken

guru@dirtydeeds:~$ 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

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

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.