Results 1 to 2 of 2

Thread: Using Proxies in CefSharp chromium browser

  1. #1
    Member
    Join Date
    Jul 2021
    Posts
    76

    Using Proxies in CefSharp chromium browser

    Hey guys, getting back into the VB game :smile:

    I've pulled up one of my old projects which helped me access web browsers via a certain proxy to login to a social media account via the selected proxy.

    After testing it out, everything still works; but the web browser in visual basics is outdated. I found a workaround using CefSharp and chromium, it seems to work the only issue I'm having after recreating everything using the cefsharp browser is the proxy function isn't working anymore. I'm not getting any errors using the same proxy method as the original program.

    Can anyone help me out?


    The button that opens up the second browser with proxy and new cefsharp browser:

    Code:

    Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click
    Form2.Show()
    MessageBox.Show("You are now under proxy " + Label9.Text + " for the account " + Label7.Text)
    UseProxy(Label9.Text)
    End Sub


    The code I'm using for the proxy settings:

    Code:

    Imports System.Runtime.InteropServices
    Imports CefSharp
    Imports CefSharp.WinForms

    Public Class Form1

    <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

    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)


    The code within my 2nd browser containing the cefsharp browser:
    Code:

    Imports System.Runtime.InteropServices
    Imports CefSharp
    Imports CefSharp.WinForms

    Public Class Form2

    <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

    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(stru ct_IPI))
    End Sub

  2. #2
    Junior Member
    Join Date
    Feb 2022
    Posts
    29
    To set up multiple proxies in the browser, you need to create new profiles and configure each profile's IP address. It all comes down to just understanding how to create new accounts in the browser.
    Unfortunately, I can't give you specific instructions about the code when writing the browser since I often buy ready-made code for my bots and refine it. For example, I bought a parsing program from https://proxycrawl.com/scraping-with...kconnect-proxy, and I was quite satisfied with this product.
    I think that you need to look for ready-made and written codes to compare your own and someone else's work. Good luck!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41