Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB.NET Proxy Question....

Status
Not open for further replies.

TeachMe1

Programmer
Dec 3, 2016
1
US
I am interested in learning more about proxy connections. I've been doing a little testing with connecting to proxies through the HttpWebRequest & using the request.Proxy & request.Timeout. But I've noticed that it seems to be a little difficult trying to move on to the next proxy after checking for 5 seconds. The program will NOT continue on without finishing the connection to the current proxy being checked on the list which FAR exceeds the 5 second limit that I'm trying to create.

Say I want the proxy to try connecting for only 5 seconds, then moving on to the next. If that proxy didn't connect within 5 seconds, it should then be added to the "Failed" proxy list, then the next proxy in line should be checked & so on. How would I accomplish this?

Here is the code that I've come up with thus far:
Code:
Dim ProxyLine As Integer = 0

Sub ProxyChecker()
        Dim i As Integer = 0
        Do Until i = ListBox1.Items.Count
            Dim myproxy As WebProxy
            Dim proxynumber As String = ListBox1.Items(ProxyLine)
            Try
                'Show progress in form:
                Me.Text = "Yell Proxy Checker - Checking Proxy # " & ListBox1.Items(ProxyLine) & "  -  " & ProxyLine + 1 & "/" & ListBox1.Items.Count
                'Show selected proxy being tested in listbox1:
                ListBox1.SelectedItem = ListBox1.Items(ProxyLine)

                myproxy = New WebProxy(proxynumber)
                Dim request As HttpWebRequest = HttpWebRequest.Create("[URL unfurl="true"]https://www.MyCrappyWebsite.com/")[/URL]
                request.UserAgent = "Mozilla/5.0 (Windows NT x.y; rv:10.0) Gecko/20100101 Firefox/10.0"
                request.Timeout = 5000
                request.Proxy = myproxy
                Dim response As HttpWebResponse = request.GetResponse

                'SUCCESSFULLY CONNECTED:
                TextBox2.Text += proxynumber & vbCrLf

            Catch ex As Exception
                'FAILED CONNECTION:
                TextBox3.Text += proxynumber & vbCrLf
            End Try
            'Increment ProxyLine:
            ProxyLine += 1

Loop

Again, I'm trying to connect for only 5 seconds & if that proxy doesn't connect within that time period, then send it to the "FAILED" list, & continue on to the next proxy in line.

Would appreciate the support!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top