Jump to content

[Vb.net] How to add proxy to your program.[Proxy code ONLY]


Dir50

Recommended Posts

Public Structure Struct_INTERNET_PROXY_INFO
  Public dwAccessType As Integer
  Public proxy As IntPtr
  Public proxyBypass As IntPtr
    End Structure
    <Runtime.InteropServices.DllImport("wininet.dll", SetLastError:=True)> _
    Private Shared Function InternetSetOption(ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, ByVal lpdwBufferLength As Integer) As Boolean
    End Function

    Private Sub PROXYSET(ByVal strProxy As String)
  WebBrowser1.ScriptErrorsSuppressed = True
  Const INTERNET_OPTION_PROXY As Integer = 38
  Const INTERNET_OPEN_TYPE_PROXY As Integer = 3
  Dim struct_IPI As Struct_INTERNET_PROXY_INFO
  struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY
  struct_IPI.proxy = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(strProxy)
  struct_IPI.proxyBypass = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi("local")
  Dim intptrStruct As IntPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))
  System.Runtime.InteropServices.Marshal.StructureToPtr(struct_IPI, intptrStruct, True)
  Dim iReturn As Boolean = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))
    End Sub  

 

 

You will make a button , duble click it and

 

Dim proxy as string = "Proxy IP"
PROXYSET(proxy)
Dim proxy as string = "xxx.xxx.xxx.xxx:8080" 'or  "xxx.xxx.xxx.xxx:80" 

After that you can open every site and your ip will be : xxx.xxx.xxx.xxx

 

Thats all , enjoy

Link to comment
Share on other sites

φιλε το WebBrowser1.ScriptErrorsSuppressed = True

  Const INTERNET_OPTION_PROXY As Integer = 38

  Const INTERNET_OPEN_TYPE_PROXY As Integer = 3

  Dim struct_IPI As Struct_INTERNET_PROXY_INFO

  struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY

  struct_IPI.proxy = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(strProxy)

  struct_IPI.proxyBypass = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi("local")

  Dim intptrStruct As IntPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))

  System.Runtime.InteropServices.Marshal.StructureToPtr(struct_IPI, intptrStruct, True)

  Dim iReturn As Boolean = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))

    End Sub

που το βαζω? το δευτερο script μπαινει στο button το πρωτo?

Link to comment
Share on other sites

Έχω την εντύπωση ότι το proxy αυτό λειτουργεί μόνο για I.E. όμως.

swsta , aytos to 8elei gia idi iparxon webbrowser , aytos o (default) webbrowser pou xrisimopoiei to .net framework einai o IE opote den iparxei provlima :)
Link to comment
Share on other sites

swsta , aytos to 8elei gia idi iparxon webbrowser , aytos o (default) webbrowser pou xrisimopoiei to .net framework einai o IE opote den iparxei provlima :)

 

Ναι αλλά έχω την εντύπωση ότι χρειάζεται restart o browser ή refresh της σελίδας για να λειτουργήσει ο proxy (αν θυμάμαι καλά γιατί έχω ξαναχρησιμοποιήσει το API αυτό νομίζω.) διόρθωσε με αν κάνω λάθος.

Link to comment
Share on other sites

  • 1 month later...

C# version of code pieces

 

public struct Struct_INTERNET_PROXY_INFO
{
public int dwAccessType;
public IntPtr proxy;
public IntPtr proxyBypass;
}
[Runtime.InteropServices.DllImport("wininet.dll", SetLastError = true)]
private static bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength)
{
}

private void PROXYSET(string strProxy)
{
WebBrowser1.ScriptErrorsSuppressed = true;
const int INTERNET_OPTION_PROXY = 38;
const int INTERNET_OPEN_TYPE_PROXY = 3;
Struct_INTERNET_PROXY_INFO struct_IPI = default(Struct_INTERNET_PROXY_INFO);
struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
struct_IPI.proxy = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(strProxy);
struct_IPI.proxyBypass = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi("local");
IntPtr intptrStruct = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI));
System.Runtime.InteropServices.Marshal.StructureToPtr(struct_IPI, intptrStruct, true);
bool iReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI));
}

string proxy = "Proxy IP";
[] PROXYSET = new[];
//or  "xxx.xxx.xxx.xxx:80"  
string proxy = "xxx.xxx.xxx.xxx:8080";

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now


×
×
  • Create New...