Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //SOURCE: Rogue: http://thebot.net/threads/tut-proxy-support-in-vb-net-c.142717/
- /*C#
- Spoiler
- STEP 1
- This code is accessing the .dll to enable the use of proxies.
- Goes at the top of the class (anywhere really but lets be orginaized)
- PrivateDeclareAuto*/
- [DllImport("wininet.dll")]
- static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);
- /*STEP 2
- Now we must create a structure so that the proxy only affects the webbrowser in your application. Not your actual webbrowser
- (IE, Chrome, Firefox, etc.)
- */
- public struct Struct_INTERNET_PROXY_INFO {
- public int dwAccessType;
- public IntPtr proxy;
- public IntPtr proxyBypass;
- }
- //STEP 3
- //Now that we have done that we can now create the function to call and set the proxy.
- void RefreshIESettings(string strProxy) {
- const int INTERNET_OPTION_PROXY = 38;
- const int INTERNET_OPEN_TYPE_PROXY = 3;
- Struct_INTERNET_PROXY_INFO s_IPI;
- s_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
- s_IPI.proxy = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(strProxy);
- s_IPI.proxyBypass = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi("Global");
- IntPtr intptrStruct = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(System.Runtime.InteropServices.Marshal.SizeOf(s_IPI));
- System.Runtime.InteropServices.Marshal.StructureToPtr(s_IPI, intptrStruct, true);
- InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(s_IPI));
- }
- //STEP 4
- //Now to call the sub we just use 1 line of code:
- RefreshIESettings("IP:PORT");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement