Advertisement
BaSs_HaXoR

How to get a PROXY IN C# Webbrowser

Oct 19th, 2014
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1. //SOURCE: Rogue: http://thebot.net/threads/tut-proxy-support-in-vb-net-c.142717/
  2.  
  3. /*C#
  4. Spoiler
  5. STEP 1
  6. This code is accessing the .dll to enable the use of proxies.
  7. Goes at the top of the class (anywhere really but lets be orginaized)
  8.  
  9. PrivateDeclareAuto*/
  10.    
  11.     [DllImport("wininet.dll")]
  12.     static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);
  13.  
  14. /*STEP 2
  15. Now we must create a structure so that the proxy only affects the webbrowser in your application. Not your actual webbrowser
  16. (IE, Chrome, Firefox, etc.)
  17. */
  18.  
  19. public struct Struct_INTERNET_PROXY_INFO {
  20.    
  21.     public int dwAccessType;
  22.    
  23.     public IntPtr proxy;
  24.    
  25.     public IntPtr proxyBypass;
  26. }
  27.  
  28. //STEP 3
  29. //Now that we have done that we can now create the function to call and set the proxy.
  30.  
  31.     void RefreshIESettings(string strProxy) {
  32.         const int INTERNET_OPTION_PROXY = 38;
  33.         const int INTERNET_OPEN_TYPE_PROXY = 3;
  34.         Struct_INTERNET_PROXY_INFO s_IPI;
  35.         s_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
  36.         s_IPI.proxy = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(strProxy);
  37.         s_IPI.proxyBypass = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi("Global");
  38.         IntPtr intptrStruct = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(System.Runtime.InteropServices.Marshal.SizeOf(s_IPI));
  39.         System.Runtime.InteropServices.Marshal.StructureToPtr(s_IPI, intptrStruct, true);
  40.         InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(s_IPI));
  41.     }
  42. //STEP 4
  43. //Now to call the sub we just use 1 line of code:
  44.  
  45. RefreshIESettings("IP:PORT");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement