AusGamers Forums
Show: per page
1
Gurus - How can I set a socks5 proxy using C# ($50USD reward)
smashcrab
Brisbane, Queensland
41 posts

I'm looking for a way to automatically set a Socks5 proxy in Windows system settings / Internet explorer. I need some c# code to achieve this, as part of a greater SSH Tunnelling application.

I've been trying to get this working for about 2 weeks now, with no luck - I've brought the question up on stackoverflow and reddit with no good responses there either so now I'm offering a $50USD reward.

More detail here:
http://stackoverflow.com/questions/8866614/automatically-setting-internet-explorer-windows-to-use-a-socks5-proxy-using-c-sh
08:48am 17/01/12 Permalink
system
Internet
--
08:48am 17/01/12 Permalink
Eorl
Brisbane, Queensland
4909 posts
I have no clue what your talking about, but I googled and found obviously some of your posts, but I also found this http://www.starksoft.com/prod_proxy.html. Not sure if that's actually what you need, but that's what I got out of googling.
08:55am 17/01/12 Permalink
smashcrab
Brisbane, Queensland
42 posts
Cheers Eorl, that actually does look useful for a separate project :)
However I need to be able to control proxy settings system wide for this to work, not just for requests within the app itself
09:07am 17/01/12 Permalink
gamer
2225 posts
Google "C# changing registry settings"

and then open regedit and take a good look at

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings

if you cant work it out from there you probably shouldn't be programming.
09:34am 17/01/12 Permalink
Nathan
Brisbane, Queensland
3912 posts
Except direct meddling with Microsoft's section of the registry is not supported and may break in future versions of windows. If you dont know that you probably shouldn't be programming real applications.

The right way is to find the Win32 API function that provides a supported interface, which appears to be InternetSetOption()

Check out http://msdn.microsoft.com/en-us/library/windows/desktop/aa385384(v=vs.85).aspx and then you'll have to do [DllImport]. Googling "c# internetsetoption" appears to turn up results from other people who've done similar.
09:58am 17/01/12 Permalink
gamer
2226 posts
Yeah changing a couple of proxy settings will break "future versions of windows" - better listen to Nath! ... not

My solution you can turn on off proxy in about 1-3 lines of code. Nathans is over complicated and a massive time waste.

K.I.S.S.

last edited by gamer at 10:16:48 17/Jan/12
10:14am 17/01/12 Permalink
Nathan
Brisbane, Queensland
3913 posts
Yeah changing a couple of proxy settings will break "future versions of windows" - better listen to Nath! ... not
I guess you dont read The Old New Thing, a blog by a senior Microsoft developer about (among other things) application compatibility problems. Go through the archives and there's many, many stories of applications that have either been broken or simply dont work right on all machines, simply because they with mess Windows internals instead of using Microsoft's supported API.

But if you want to be a "Works For Me" programmer, go right ahead.
10:18am 17/01/12 Permalink
Pinky
Melbourne, Victoria
12204 posts
Nathan, you're wasting your time.
10:29am 17/01/12 Permalink
trog
AGN Admin
Brisbane, Queensland
35458 posts
I guess you dont read The Old New Thing, a blog by a senior Microsoft developer about (among other things) application compatibility problems. Go through the archives and there's many, many stories of applications that have either been broken or simply dont work right on all machines, simply because they with mess Windows internals instead of using Microsoft's supported API.
It has been a very common problem with games, especially in things like mods for Half-Life. It used to be a massive pain in the ass for a certain Counter-Strike mod (the name of which eludes me) which would not use the HL API to do something and instead used an unsupported custom way of doing things. Each new HL release, the mod would break horribly and they'd have to do a re-release a few days later once they figured out how to do it in the new version. It was a total pain in the ass for everyone.

So you can do things correctly once, or do them "incorrectly" multiple times. If you have unlimited spare time then it is probably not a hassle to do the registry hack.
10:30am 17/01/12 Permalink
smashcrab
Brisbane, Queensland
43 posts
If you read the link I posted, I've already tried the registry method and its just not reliable. Neither Internet Explorer itself, or other applications using IE settings will use them immediately, and most of the time you need to open up the proxy config screen before they will be noticed. Not a solution.

I've also looked into the internetsetoptions stuff, and I'm using for HTTP proxies via the PoshHTTP class, where it works perfectly. However it doesnt seem to support setting SOCKS5 proxies this way :(
10:30am 17/01/12 Permalink
Dazhel
Gold Coast, Queensland
4330 posts
Yeah changing a couple of proxy settings will break "future versions of windows" - better listen to Nath! ... not
My solution you can turn on off proxy in about 1-3 lines of code. Nathans is over complicated and a massive time waste.


It's actually your solution that's more complicated, just that the complications aren't visible until years later when they're causing unnecessary problems for the poor sap that's replaced you, your former company and Microsoft, or any/all three.
Nathan's solution is well worth the extra 10 minutes it might take to do it properly the first time.
10:31am 17/01/12 Permalink
Hogfather
Cairns, Queensland
11683 posts
HACK THE GIBSON
10:45am 17/01/12 Permalink
Nathan
Brisbane, Queensland
3914 posts
Given that the registry is just a data-store, you have no way of knowing whether SetInternetOption() simply updates the registry and does nothing else; or whether it reaches out to tell active instances of IE that settings have changed. Or whether it will do that in the future, or provide some other key functionality that simply editing a data store cannot provide.

And of course, it actually looks pretty trivial to do the right way - eg http://www.pinvoke.net/default.aspx/wininet/internetsetoption.html assuming SetInternetOption is the right way to tell Windows about a SOCKS5 proxy - it might turn out there is no supported way to do so. But you want to establish that before going into unsupported territory.
10:45am 17/01/12 Permalink
Nathan
Brisbane, Queensland
3915 posts
smashcrab, the MSDN doc mentions you need to call InternetSetOption() with INTERNET_OPTION_REFRESH to make IE aware of the changes.
10:55am 17/01/12 Permalink
kos
Germany
1921 posts
Oh man... please tell me gamer doesn't program for a living.
11:06am 17/01/12 Permalink
smashcrab
Brisbane, Queensland
44 posts
If its seriously that simple I'll be pissed..
So I set socks proxy using registry (since there is no equivalent to do it with internetsetoptions alone), and then call an INTERNET_OPTION_REFRESH ?

I'm just about out the door right now, but I'll test when I get back in a few hours. Can't believe I never attempted mixing the methods *sigh*
11:06am 17/01/12 Permalink
Nathan
Brisbane, Queensland
3916 posts
As far as I can tell, it is supported via InternetSetOptions

InternetSetOption() with INTERNET_OPTION_PER_CONNECTION_OPTION

You then want a connection list with

INTERNET_PER_CONN_PROXY_SERVER
"Sets or retrieves a string containing the proxy servers."

The key bit being the that its servers - plural - ie the string format is not necessarily just an IP:port
The impression I get from http://support.microsoft.com/kb/226473 is that you can probably tell give it proxy "socks=socks://IP:port".

A simple app that spits out the results from InternetQueryOption() INTERNET_OPTION_PER_CONNECTION_OPTION should tell you the right format for the proxy string if you configure the SOCKS proxy through the GUI first. I assume its documented in MSDN somewhere, but so far my Google-fu is failing.
11:24am 17/01/12 Permalink
smashcrab
Brisbane, Queensland
45 posts
Holy s***, it actually works. Thankyou so much Nathan, I'd actually tried all sorts of ways to get that to take a socks proxy and it just wouldn't take it because I had the wrong format.

All I had to do in the end was PoshHttp.Proxies.SetProxy("socks=socks://$ip:$port");

Message me with a paypal account and I'll send $50 your way :) Cheers mate
01:54pm 17/01/12 Permalink
Jc_23
Brisbane, Queensland
339 posts
Got any other problems relating to health and fitness or metalwork that need addressing smashcrab? :)

02:17pm 17/01/12 Permalink
smashcrab
Brisbane, Queensland
46 posts
lol nah man I'm good now :P
02:22pm 17/01/12 Permalink
IVY_MiKe
Canberra, Australian Capital Territory
655 posts
f*****g lol.

I knew gamer's first post was too good to be true, and then.... BAM he righted the world by being 'gamer' in the subsequent post

whilst that might be a suitable 'tweak' for one or two systems mate, it's a rubbish solution in an enterprise (or even serious Sml-Med Business) environment.
06:09pm 17/01/12 Permalink
Morgan
Brisbane, Queensland
3802 posts
I think gamer was fine right up until he started arguing his solution is better than the official, supported, documented API method. His solution does works it's just not ideal. He should have KISS'd and STFU.
06:29pm 17/01/12 Permalink
Dazhel
Gold Coast, Queensland
4336 posts
Sure, the solution might work, right up until the point where some innocuous windows update patch gets applied at 3am on a Sunday morning and nobody at the customer site has a clue as to why it suddenly stopped working.
06:59pm 17/01/12 Permalink
HyperJ
Brisbane, Queensland
404 posts
Oh man... please tell me gamer doesn't program for a living.

Just waiting for him to say it's OK because it's "Agile"
08:19pm 17/01/12 Permalink
system
Internet
--
08:19pm 17/01/12 Permalink
AusGamers Forums
Show: per page
1
This thread is archived and cannot be replied to.
 

Advertise with Us | Download Media Kit | Privacy Policy | Contact Us
© Copyright 2001-2014 AusGamers™ Pty Ltd. ACN 093 772 242.
A Mammoth Media web development / Australian VPS Hosting by Mammoth Networks