Giter VIP home page Giter VIP logo

socks5's Introduction

socks5 Package

A simple SOCKS 5 client written in Tcl that supports both the BIND and CONNECT commands.

Known Limitations

  • Support for username/password authentication only
  • No support for UDP ASSOCIATE command

License

This program is released under the BSD license.

Sample

The socks5 package can be used to SOCKS enable the http package. This is useful for passing all http requests through the Tor network, for example. Assuming you have Tor running on your local system and listening for connections on port 9050, the following sample code demonstrates how to enable http use of Tor.

package require Tcl 8.5
package require socks5
package require tls 1.6
package require http 2.7

proc httpsConnect {args} {
    # Separate options from mandatory arguments
    set opts [lrange $args 0 end-2]
    lassign [lrange $args end-1 end] host port
    # Establish connection with SOCKS 5
    set sock [::socks5::connect {*}$opts $host $port]
    # Enable SSL on open socket (make sure we're using tls rather
    # than ssl3)
    ::tls::import $sock -tls1 1
    return $sock
}

http::register http 80 ::socks5::connect
http::register https 443 ::httpsConnect

socks5::configure -proxy localhost -proxyport 9050

# Retrieve check.torproject.org to confirm we are using Tor
set token [http::geturl "https://check.torproject.org" -channel stdout]
http::cleanup $token

Usage

The socks5 library is distributed as a Tcl package and can be loaded using the package require command:

package require socks5 0.1

socks5::configure

Usage: socks5::configure <args>

Use socks5::configure to configure the library for operations. The following options are available:

Option Description
-proxy IP or hostname for the proxy server
-proxyport Port number on which the proxy server operates (default: 1080)
-bindtimeout Timeout (in milliseconds) when waiting for an incoming connection via socks5::bind
-username Username (for username/password authentication) (default: )
-password Password (for username/password authentication) (default: )

Example:

socks5::configure -proxy localhost -proxyport 1080 -bindtimeout 2000

socks5::connect

Usage: socks5::connect ?-async? ?-myaddr addr? ?-myport port? <host> <port>

Establishes a connection with a remote host through the configured proxy.

Example:

socks5::connect www.google.com 80

socks5::bind

Usage: socks5::bind ?-myaddr addr? ?-myport port? <host> <port> <command>

Requests the proxy open a TCP port for listening and wait for an incoming connection from the specified host and port.

The command parameter will be evaluated at the global scope when the incoming connection is established. Two parameters will be appended. The first indicates the type of response from the proxy, while the second depends on the response. The following table identifies expected response codes.

Response Argument Description
ok channel handle Indicates an incoming connection was esablished. The channel handle may be used to communicate with the remote host.
timeout error message Indicates the -bindtimeout expired while waiting for an incoming connection.
error error message Indicates some sort of error occurred with the proxy. The error message provides further details.

Example:

proc handle_connect {result arg} {
   if {$result eq "ok"} {
      puts "connection established via channel $arg"
   } elseif {$result eq "timeout"} {
      puts "timeout expired while waiting for connection"
   } elseif {$result eq "error"} {
      puts "error from proxy while waiting for connection: $arg"
   }
}

socks5::bind ftp.cdrom.com 21 handle_connect

socks5's People

Contributors

dongola7 avatar laomaiweng avatar mystery-x avatar

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.