[REQ] Vb.net proxy tutorial

Discussion in '.NET' started by hornetss, Mar 7, 2010.

  1. hornetss

    hornetss Make Money Online

    Joined:
    Nov 13, 2009
    Messages:
    60
    Likes Received:
    0
    Trophy Points:
    0
    I can't seem to find a tutorial anywhere on setting up a proxy with vb.NET.

    If anybody here can post a tutorial on how to test, and connect to a proxy, it would great.


    Thanks,
    Hornetss
     
  2. High Definition

    High Definition Make Money Online

    Joined:
    Mar 14, 2010
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    127.0.0.1
    LMAO..Its not "vBulletin.Net", its "Visual Basic.NET" .......

    Anyways, here's one way how to do it..

    Code:
    
    Public Structure Struct_PROXY
            Public dwAccessType As Integer
            Public proxy As IntPtr
            Public pxyby As IntPtr
        End Structure
    
        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
    
        Private Sub refreshproxy(ByVal strProxy As String)
            Const IOProxy As Integer = 38
            Const IProxy As Integer = 3
            Dim st_SP As Struct_PROXY
    
            st_SP.dwAccessType = IProxy
            st_SP.proxy = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi(strProxy)
            st_SP.pxyby = System.Runtime.InteropServices.Marshal.StringToHGlobalAnsi("Global")
    
            Dim intptrStruct As IntPtr = System.Runtime.InteropServices.Marshal.AllocCoTaskMem(System.Runtime.InteropServices.Marshal.SizeOf(st_SP))
            System.Runtime.InteropServices.Marshal.StructureToPtr(st_SP, intptrStruct, True)
            InternetSetOption(IntPtr.Zero, IOProxy, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(st_SP))
    
        End Sub
    
    

    Usage:

    Code:
    refreshproxy("IP:PORT")



    If this seems more complicated to you there is an easy way also...:p
     
  3. hornetss

    hornetss Make Money Online

    Joined:
    Nov 13, 2009
    Messages:
    60
    Likes Received:
    0
    Trophy Points:
    0
    Nice, thanks.

    It replaces vb .net to vbulletin.net
     
  4. High Definition

    High Definition Make Money Online

    Joined:
    Mar 14, 2010
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    127.0.0.1
    oh..Word sensor, alright..
     
  5. hornetss

    hornetss Make Money Online

    Joined:
    Nov 13, 2009
    Messages:
    60
    Likes Received:
    0
    Trophy Points:
    0
    Hey I'm making a proxy checker but I can't seem to figure out how to make this time out after an X amount of seconds.

    Code:
            For Each ip In TextBox1.Lines
                refreshproxy(ip)
                WebBrowser1.Navigate("http://google.com")
    
                While WebBrowser1.ReadyState <> WebBrowser1.ReadyState.Complete
                    Application.DoEvents()
                End While
    
                If WebBrowser1.Document.Body.InnerHtml.Contains("<TEXTAREA") Then
                    ListBox1.Items.Add(ip)
                End If
    
            Next
     
  6. High Definition

    High Definition Make Money Online

    Joined:
    Mar 14, 2010
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    127.0.0.1
    You need to specify the port number also to use it..

    And you can add a timer to accomplish it..Like suppose

    timer1.interval=(6000 * 20)
    timer1.start()

    If you receive the reply under those 20 seconds the proxy is good else proxy is bad..

    I used 6000 * 20 because timer takes the inputs in milliseconds..So its wise to first convert it into second so multiplying it with 6000
     
  7. Hydrogen2012

    Hydrogen2012 Make Money Online

    Joined:
    Dec 30, 2009
    Messages:
    180
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Down in a Hole
    Unless you have to, I'd stay away from the browser control. A much more accruate and efficent way to go about this would be to use the HTTPWEBRequest functions it's much more stable and will speed up your application dramatically and then using a proxy is much more easier then the Hack shown above (which by the way, is the only way to change the browser proxy) It's ugly as hell but is the way to go about it.

    If you decide to switch and go to the httpwebrequest route then this is how you specify a proxy using that.

    Code:
                        Dim IP as string = "192.168.1.1"
                        Dim Port as string = "80"
                        Dim proxy As New WebProxy(IP & ":" & Port, True)  ' True = Bypass on Local IPs/Domains
                        objWebRequest.Proxy = proxy  ' objWebRequest would be setup before all this and contain your httpwebrequest
    
     
  8. syanide

    syanide Make Money Online

    Joined:
    Jan 7, 2010
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    or even use the webclient class.. It's a wrapper for the httpwebrequest object
     
  9. hornetss

    hornetss Make Money Online

    Joined:
    Nov 13, 2009
    Messages:
    60
    Likes Received:
    0
    Trophy Points:
    0
    Thanks for the help guys, but using the web browser code, how do I switch back to a direct connection?
     
  10. scottmobster

    scottmobster Make Money Online

    Joined:
    Jan 5, 2010
    Messages:
    27
    Likes Received:
    0
    Trophy Points:
    0
    No one ever answered how to switch back for you. It doesn't save the IP... so when you unload the w b control, it will revert to the default windows settings, if that has no IP, then that would accomplish your goal.
     
  11. yesrams

    yesrams Make Money Online

    Joined:
    May 3, 2010
    Messages:
    20
    Likes Received:
    0
    Trophy Points:
    0
    I am searching for this.. Thank you for examples.
     
  12. MarkusJNZ

    MarkusJNZ Make Money Online

    Joined:
    May 12, 2010
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Hi, slightly off topic but if you want to use a timer to see how long a process has run there is a StopWatch object in the System.Diagnostics namespace, it works a treat for seeing how long processes are taking.

    Cheers
    Mark
     
  13. Hydrogen2012

    Hydrogen2012 Make Money Online

    Joined:
    Dec 30, 2009
    Messages:
    180
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Down in a Hole


    1.) Spawn a Timer Control
    2.) Set Interval to 1000 (1000ms = 1second)
    3.) Enable Timer when thread starts
    4.) Each tick increment a Integer in your thread you have set for timing
    5.) When thread is ending Disable the Timer and output the result of Integer where ever you need it.
     
  14. dkaiser81

    dkaiser81 Make Money Online

    Joined:
    Dec 8, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Here is the code to switch back to a direct connection.

    Code:
    refreshProxy(":")
    :top:
     

Share This Page