Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/fangdingjun/socks-go

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/fangdingjun/socks-go

  • v0.0.0-20220901073602-f35f0e0139ec
  • Source
  • Go
  • Socket score

Version published
Created
Source

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

FAQs

Package last updated on 01 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc