CSharp .Net Tutorial: Change Proxy

James Cloud
Introduction

Proxies are used to maintain anonymity when browsing on-line. A proxy achieves this by changing the I.P. Address of the user so that the website thinks the user is coming from a different location. Though proxies are entirely legal, they can be used for questionable activities. This article is to be used for security purposes only and not for malicious intent.

NOTE: this tutorial involves the editing and modification of the Window's registry through source code. Always practice extreme caution when accessing the system registry. Editing or delete system keys or data may cause your computer to malfunction or stop working entirely.

Start at step one below, to begin the process of change Internet Explorer's proxy settings.

Step One - Necessary Declarations

Internet Explorer's proxy settings can be easily accessed through the system registry. However, to be able to access the registry you must include a reference to 'Microsoft.Win32'. Add this code to your project's using section,

using Microsoft.Win32;

Step Two - Create a Proxy Changing Function

To easily change, enable, and disable the proxy settings, we will create a void called setProxy using the source code found here,

public void setProxy(string IPADDRESS, int enable)
{
RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);
registry.SetValue("ProxyEnable", enable);
registry.SetValue("ProxyServer", IPADDRESS);
}

The function just created will take the first parameter and set the registry key relating to the proxy server to this value. It will also enable or disable the usage of proxies in Internet Explorer entirely depending of the value supplied in the second parameter.

Conclusion

To change the proxy, simply execute the setProxy() function and give the proxy address and the first parameter and either 1 or 0 as the second if you would like to enable or disable the proxy. Here is an example,

// Disable the Proxy and Set it to the Local Host
setProxy("127.0.0.1", 0);

The above code will reset the proxy address to the local host address(127.0.0.1) and disable Internet Explorer from using the proxy settings.

Published by James Cloud

I like to program and do basically anything that has to do with technology and computers.  View profile

To comment, please sign in to your Yahoo! account, or sign up for a new account.