socks

package module
v0.0.0-...-ddaf702 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2014 License: BSD-2-Clause Imports: 4 Imported by: 0

README

SOCKS

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

##Quick Start ###Get the package

go get -u "github.com/hailiang/socks"

###Import the package

import "github.com/hailiang/socks"

###Create a SOCKS proxy dialing function

dialSocksProxy := socks.DialSocksProxy(socks.SOCKS5, "127.0.0.1:1080")
tr := &http.Transport{Dial: dialSocksProxy}
httpClient := &http.Client{Transport: tr}

##Complete Documentation http://go.pkgdoc.org/github.com/hailiang/socks

##Alternatives http://code.google.com/p/go/source/browse/?repo=net#hg%2Fproxy

Documentation

Overview

Package socks implements a SOCKS (SOCKS4, SOCKS4A and SOCKS5) proxy client.

A complete example using this package:

package main

import (
	"github.com/hailiang/socks"
	"fmt"
	"net/http"
	"io/ioutil"
)

func main() {
	dialSocksProxy := socks.DialSocksProxy(socks.SOCKS5, "127.0.0.1:1080")
	tr := &http.Transport{Dial: dialSocksProxy}
	httpClient := &http.Client{Transport: tr}

	bodyText, err := TestHttpsGet(httpClient, "https://github.com/about")
	if err != nil {
		fmt.Println(err.Error())
	}
	fmt.Print(bodyText)
}

func TestHttpsGet(c *http.Client, url string) (bodyText string, err error) {
	resp, err := c.Get(url)
	if err != nil { return }
	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil { return }
	bodyText = string(body)
	return
}

Index

Constants

View Source
const (
	SOCKS4 = iota
	SOCKS4A
	SOCKS5
)

Constants to choose which version of SOCKS protocol to use.

Variables

This section is empty.

Functions

func DialSocksProxy

func DialSocksProxy(socksType int, proxy string) func(string, string) (net.Conn, error)

DialSocksProxy returns the dial function to be used in http.Transport object. Argument socksType should be one of SOCKS4, SOCKS4A and SOCKS5. Argument proxy should be in this format "127.0.0.1:1080".

Types

This section is empty.

Jump to

Keyboard shortcuts

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