Git Product home page Git Product logo

socks-go's Introduction

socks-go

A socks proxy protocol implemented by golang, support socks 4, 4a and 5.

Only CONNECT command support now.

usage example

server:

// listen 1080 and act as socks server
// support socks4, socks4a and socks5

package main

import (
    socks "github.com/fangdingjun/socks-go"
    "log"
    "net"
    "time"
)

func main() {
    conn, err := net.Listen("tcp", ":1080")
    if err != nil {
        log.Fatal(err)
    }

    for {
        c, err := conn.Accept()
        if err != nil {
            log.Println(err)
            continue
        }

        log.Printf("connected from %s", c.RemoteAddr())

        d := net.Dialer{Timeout: 10 * time.Second}
        s := socks.Conn{Conn: c, Dial: d.Dial}
        go s.Serve()
    }
}

client:

// visit https://www.google.com through socks proxy server

package main

import (
    "bufio"
    "crypto/tls"
    socks "github.com/fangdingjun/socks-go"
    "io"
    "log"
    "net"
    "net/http"
    "os"
)

func main() {
    // connect to socks server
    c, err := net.Dial("tcp", "localhost:1080")
    if err != nil {
        log.Fatal(err)
    }
    defer c.Close()

    sc := &socks.Client{Conn: c}

    // connect to remote server
    if err := sc.Connect("www.google.com", 443); err != nil {
        log.Fatal(err)
    }

    // tls
    conn := tls.Client(sc, &tls.Config{ServerName: "www.google.com"})
    if err := conn.Handshake(); err != nil {
        log.Fatal(err)
    }

    // send http request
    req, err := http.NewRequest("GET", "https://www.google.com/", nil)
    if err != nil {
        log.Fatal(err)
    }
    req.Write(conn)

    bio := bufio.NewReader(conn)

    // read response
    res, err := http.ReadResponse(bio, req)
    if err != nil {
        log.Fatal(err)
    }
    defer res.Body.Close()

    io.Copy(os.Stdout, res.Body)
}

socks-go's People

Contributors

fangdingjun 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

Watchers

 avatar  avatar  avatar  avatar  avatar

socks-go's Issues

But I can't add login and password to my code.

Hello.
Thank you for your code.
I am not a programmer. But I sometimes make small programs for myself. I like your code and without password my program works.

I looked at all your files and tests. But I can't add login and password to my code.
How do I add login and password to server and client (I haven't tried it in client yet because I don't have a working server with password)?

func main() {
	user := "admin"
	pass := "pass"

...
s := socks.Conn{Conn: c, Dial: d.Dial, Auth: &passwordAuth{user, pass}}
err - undeclared name: passwordAuthcompiler

This doesn't work either and other different options:
s := socks.Conn{Conn: c, Dial: d.Dial, Auth: socks.AuthService.Authenticate(user, pass, conn)}

Thanks for your help!

I was thinking about adding dynamic username and password function.

I have seen the code at:

And I think it's possible to enhance this service with authentication and\or authorization mechanism.

  • Authorization ie based on IP acl that will match the src address to a whitelist
  • Authentication ie a function that will know to match the incomming connection username and password against some simple mechanism like htaccess\sqlite\redis\msysql.

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.