none
How to change Socks 4/5 using vb.net RRS feed

  • Question

  • hi

    how to use Socks 5 proxies in Internet Explorer. I have code for http proxies but that code is not working for Socks proxies.

    Anyone has such code? Please provide some pointers.

    I'm basically doing IE automation in VB.NET, and I need code to use socks proxies using IE.

    the code am used that change only HTTP PROXY :

    ####################################################

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

        Public Structure Struct_INTERNET_PROXY_INFO
            Public dwAccessType As Integer
            Public proxy As IntPtr
            Public proxyBypass As IntPtr
        End Structure

        Private Sub UseProxy(ByVal strProxy As String)
            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 = Marshal.StringToHGlobalAnsi(strProxy)
            struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local")

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

            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

    Private Sub ButtonX4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX4.Click
            UseProxy(textBox4.text)
           WebBrowser2.Navigate(textBox1.text)
               
        End Sub

        ''''''''''''''''''''''End proxy'''''''''''''''''''''''*

    ####################################################

    Saturday, September 7, 2019 2:00 AM

All replies

  • hi

    I want vb.net code to use Socks proxies in Internet Explorer. I have code for http proxies but that code is not working for Socks proxies.

    thank you


    • Edited by abdu bubekri Tuesday, September 3, 2019 5:51 AM
    • Merged by Alex Li-MSFT Monday, September 9, 2019 1:19 AM same case
    Tuesday, September 3, 2019 5:50 AM
  • Hi,

    Maybe you can try my code as follows:

    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            RefreshIESettings("...Your Socks Port...")
            WebBrowser1.Navigate("http://www.google.com")
        End Sub
    
        ' The structure we use for the information
        ' to be interpreted correctly by API.
        Public Structure Struct_INTERNET_PROXY_INFO
            Public dwAccessType As Integer
            Public proxy As IntPtr
            Public proxyBypass As IntPtr
        End Structure
    
        ' The Windows API function that allows us to manipulate
        ' IE settings programmatically.
        Private Declare Auto Function InternetSetOption Lib "wininet.dll" _
        (ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr,
         ByVal lpdwBufferLength As Integer) As Boolean
    
        ' The function we will be using to set the proxy settings.
        Private Sub RefreshIESettings(ByVal strProxy As String)
            Const INTERNET_OPTION_PROXY As Integer = 38
            Const INTERNET_OPEN_TYPE_PROXY As Integer = 3
            Dim struct_IPI As Struct_INTERNET_PROXY_INFO
    
            ' Filling in structure
            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")
    
            ' Allocating memory
            Dim intptrStruct As IntPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))
    
            ' Converting structure to IntPtr
            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
    
    End Class
    

    Please note that,Http proxy is used to browse web pages. Its ports are usually 80 and 8080, but there are other ports such as 3128. Socks5 proxy can be regarded as a versatile proxy. It can be used in telnet, FTP or IRC chat. The ports of such proxy are usually 1080. SOCKS5 that SOCK4 can do is available, but SOCK4 that SOCKS5 can do is not necessarily able to do.

    You can also seek for this Link.

    Hope I can help you.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 3, 2019 9:25 AM
    Moderator
  • hi thanks for your help 

    but this code i aleardy used this function change only http proxy not socks i want change the socks4-5

     
    Tuesday, September 3, 2019 10:33 PM
  • Hi,

    Some people have asked similar questions.
    The available answer is that to set the proxy settings, you can change registry entry entries.

    Another answer that may be helpful is written in Russian, and you need to translate it.

    Hope I can help you.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Wednesday, September 4, 2019 4:47 AM
    Moderator
  • i cant change it 
    Friday, September 6, 2019 11:52 PM
  • Hi,

    Maybe this link will help you.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, September 12, 2019 7:38 AM
    Moderator