socks4

package module
v1.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2022 License: MIT Imports: 8 Imported by: 15 modules, 10 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-socks4

Socks4 implementation for Go, compatible with net/proxy.

Features

  • socks4
  • socks4a

Usage

Just import _ "github.com/bdandy/go-socks4" to add socks4 support

package main

import (
	"errors"
	"log"
	"net/url"

	_ "github.com/bdandy/go-socks4"
	"golang.org/x/net/proxy"
)

func main() {
	addr, _ := url.Parse("socks4://ip:port")

	dialer, err := proxy.FromURL(addr, proxy.Direct)
	conn, err := dialer.Dial("tcp", "google.com:80")
	if err != nil {
		// handle error
		if errors.Is(err, socks4.ErrDialFailed) {
			log.Printf("invalid proxy server %s", addr)
			return
		}
		if errors.Is(err, socks4.ErrConnRejected) {
			log.Printf("google.com:80: %s", err)
			return
		}
	}
	// use opened network connection
	_ = conn
}

Tests

If you know proxy server to connect to tests should be running like this go test -socks4.url=socks4://localhost:8080

Documentation

Overview

Package socks4 implements socks4 and socks4a support for net/proxy Just import `_ "github.com/bdandy/go-socks4"` to add `socks4` support

Index

Constants

View Source
const (
	ErrWrongNetwork    = errors.String("network should be tcp or tcp4")          // socks4 protocol supports only tcp/ip v4 connections
	ErrDialFailed      = errors.String("socks4 dial")                            // connection to socks4 server failed
	ErrWrongAddr       = errors.String("wrong addr: %s")                         // provided addr should be in format host:port
	ErrConnRejected    = errors.String("connection to remote host was rejected") // connection was rejected by proxy
	ErrIdentRequired   = errors.String("valid ident required")                   // proxy requires valid ident. Check Ident variable
	ErrIO              = errors.String("i\\o error")                             // some i\o error happened
	ErrHostUnknown     = errors.String("unable to find IP address of host %s")   // host dns resolving failed
	ErrInvalidResponse = errors.String("unknown socks4 server response %v")      // proxy reply contains invalid data
	ErrBuffer          = errors.String("unable write into buffer")
)

Variables

View Source
var Ident = "nobody@0.0.0.0"

Functions

This section is empty.

Types

type Error

type Error = errors.Error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL