tags:

views:

542

answers:

3

I have a socket app that needs to have support for SOCKS 4 and 5 proxy connections, since my users may be behind firewalls. I am using WPF and C# 3.5 SP1. I see no options in the default Socket class for proxys, do I have to roll my own?

I'd prefer not to use 3rd party libs if possible - how difficult is it to enable proxy support with a standard C# Socket?

A: 

You could ask google for some info. One of the first links will lead you to Mentalis.org and their free proxy implementation. They were once well known for their free network and security stuff but the projects seem to not being maintained for a while.

But it might be worth a look anyway.

Frank Bollack
A: 

I know you said that you did not want to use 3rd party librarys if possbile, but I would like to recommend this http://www.starksoft.com/prod%5Fproxy.html.

kerchingo
A: 

It is not terribly hard but you have to read through a couple of RFCs. You need to read the RFC spec on Socks v4, Socks v4a and Socks v5. I wrote a library that will do all the work for you but if you would rather write you own that is cool too. My library was mentioned in the previous post (Starksoft). You can implement the Socks protocol using a standard TcpClient object or a Socket connection. The TcpClient is easier. You simply need to send the commands immediately after connection to your proxy server. Those command will instruct the proxy server what final end point you are interested in connecting to. There is also specs for a UDP Socks connection but it sounds like you won't be needing that.

You can find all the RFCs and generation information on wikipedia. I can't post more because this crazy stackoverflow site limits the number of hyperlinks I am allowed to 1 since I am not a regular user. Very annoying.

http://en.wikipedia.org/wiki/SOCKS

Finally, you can rip off my code if you like since it is under the MIT license and I let you do that kind of thing. :) Take at look at my class Socks4ProxyClient.cs that implements the Socks v4 protocol. The method of most interest to you is named SendCommand() located on line 282. You can find my code at Google Code. Search for Starksoft. Or you can go to my web site directly and I have link to the source code in Google.

Socks5 implementation is a little trickier with more options to specify and a little more chatter to the server but basically very similar to Socks4.

Good luck and you should implement a solution yourself if you want to learn Socks. So, kudos to you!

  • Benton
Benton Stark