# Moles with SOCKS? [closed]

Many applications that depend on network resources (such as games connecting to game servers) do not allow the user to set a proxy. There are a lot of ways to force the usage of a proxy regardless, I personally have always been a fan of a local SOCKS tunnel.

## What's that?

Instead of connecting directly, an application on your local machine listens on a locally bound address and relays any connection to a fixed endpoint using a remote SOCKS proxy.

Example: Let our target be 11.22.33.44:5555, and our remote socks proxy be 99.88.77.66:5555. Our application listens on 127.0.0.1:5555. Our route now looks like this:

connect to 127.0.0.1:5555 - relays via SOCKS proxy > 99.88.77.66:5555 - to > 11.22.33.44:5555

Your goal is to implement the local application relaying connections to the target.

## Input

• You may deviate from the order (but specify if you do).
• Address parsing is up to your language/tools of choice, but should at the very minimum support IPv4 (11.22.33.44).
• You may use builtin types of your language. (like InetSocketAddress in Java, struct in_addr in C, etc.)

## Output

No rules for output due to .

• This is , shortest answer in bytes wins.
• Standard rules apply, default loopholes are forbidden.
• You do not have to support more than 1 connection. The program may terminate after the first connection finishes.
• Program behaviour under network failures is undefined; you may crash the entire program, reject the incoming connection, do whatever you want.
• You may assume the remote SOCKS proxy's version (4/4a/5).
• Using libraries/inbuilts/etc. is encouraged, but not required.
• Stay in input scope (f.e. don't proxy all connections on the machine).

## closed as unclear what you're asking by Digital Trauma, Sriotchilism O'Zaic, NoOneIsHere, Rɪᴋᴇʀ, ArjunMar 30 '17 at 2:57

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• So the task is to create a local SOCKS server that accepts local connections (e.g. from a suitably configured browser) and connects to a remote SOCKS proxy that forwards the connection to the far end (e.g. web server)? - its not entirely clear to me. – Digital Trauma Mar 29 '17 at 20:27
• @DigitalTrauma Not a local SOCKS server, but more a local tunnel server using a fixed SOCKS proxy to forward connections to a fixed end. – F. George Mar 29 '17 at 21:15
• So just a simple local TCP port forward then? - that itself knows nothing of the SOCKS protocol? This is not really clear to me – Digital Trauma Mar 29 '17 at 22:48
• I'm not sure what else there is to explain? From the point of the connecting application it is effectively a port forward. The impementing application obviously has to know about the SOCKS protocol. I've even given a sample answer in Kotlin. – F. George Mar 30 '17 at 7:10

# Kotlin, 240 bytes

This was fun and taught me some things I didn't know about Kotlin.

import java.net.*fun a(vararg p:InetSocketAddress){ServerSocket().run{bind(p[0])
accept().let{Socket(Proxy(Proxy.Type.SOCKS,p[1])).run{connect(p[2])
inputStream.copyTo(it.outputStream)}}}}


Tested locally with:

fun main(args: Array<String>) {

Prints 5,2,0,2, which confirms an attempted SOCKS5 connection.