Advertisement
Guest User

MyCode

a guest
Aug 3rd, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 5.22 KB | None | 0 0
  1. Imports System.Net
  2. Imports System.IO
  3. Imports System.Text.RegularExpressions
  4. Imports System.Text
  5. Imports System.Threading
  6.  
  7. Public Class Form1
  8.     Const loginurl As String = "http://haraj.com.sa/login.php"
  9.     Const useragent As String = "Mozilla/5.0 (Windows NT 6.1; rv:39.0) Gecko/20100101 Firefox/39.0"
  10.     Const key_login_pat = "(?<=""key_login""\svalue="").*?(?="")"
  11.     Const postmask = "user={0}&pass={1}&sublogin=1&url=" & "http://haraj.com.sa/" & "&key_login={2}&login=دخــــول+»"
  12.     Dim cookieJar As CookieContainer
  13.  
  14.     Private Function GetStringResponse(req As HttpWebRequest)
  15.         Using res = req.GetResponse
  16.             Using strm = res.GetResponseStream
  17.                 Using rdr = New StreamReader(strm)
  18.                     Return rdr.ReadToEnd
  19.                 End Using
  20.             End Using
  21.         End Using
  22.     End Function
  23.  
  24.     Private Function get_keylogin() As String
  25.         cookieJar = New CookieContainer
  26.         Dim req = DirectCast(WebRequest.Create(loginurl), HttpWebRequest)
  27.         req.UserAgent = useragent
  28.         req.CookieContainer = cookieJar
  29.         Return Regex.Match(GetStringResponse(req), key_login_pat).Value
  30.     End Function
  31.  
  32.     Private Sub UpdateAnnounce(ByVal id As String)
  33.         id = id.Trim
  34.         MsgBox("1:  " & id)
  35.         Dim req_announce = DirectCast(WebRequest.Create("http://haraj.com.sa/update2.php?ads_id=" & id), HttpWebRequest)
  36.         req_announce.Method = "POST"
  37.         req_announce.UserAgent = useragent
  38.         req_announce.CookieContainer = cookieJar
  39.         req_announce.Referer = "http://haraj.com.sa/update2.php?ads_id=" & id
  40.         req_announce.ContentType = "application/x-www-form-urlencoded"
  41.         Dim buffer_announce = Encoding.UTF8.GetBytes("ads_id=" & id)
  42.         req_announce.ContentLength = buffer_announce.Length
  43.         Using reqStrm_user = req_announce.GetRequestStream
  44.             reqStrm_user.Write(buffer_announce, 0, buffer_announce.Length)
  45.         End Using
  46.         MsgBox("2:  " & id)
  47.         IO.File.WriteAllText("C:\" & id & ".txt", GetStringResponse(req_announce))
  48.     End Sub
  49.     Private Sub LoginAndUpdate(ByVal Username As String, ByVal Password As String)
  50.         Dim keylogin = get_keylogin()
  51.         Dim req = DirectCast(WebRequest.Create(loginurl), HttpWebRequest)
  52.         req.Method = "POST"
  53.         req.UserAgent = useragent
  54.         req.CookieContainer = cookieJar
  55.         req.Referer = loginurl
  56.         req.ContentType = "application/x-www-form-urlencoded"
  57.  
  58.         Dim buffer = Encoding.UTF8.GetBytes(String.Format(postmask, Username, Password, keylogin))
  59.         req.ContentLength = buffer.Length
  60.         Using reqStrm = req.GetRequestStream
  61.             reqStrm.Write(buffer, 0, buffer.Length)
  62.         End Using
  63.  
  64.         Dim resp As String = GetStringResponse(req)
  65.         If resp.Contains("تسجيل الخروج") Then
  66.             MessageBox.Show("تم تسجيل الدخول بنجاح" & vbNewLine & "جارى جلب ارقام الاعلانات الخاصة بهذا الحساب", "تم تسجيل الدخول بنجاح", MessageBoxButtons.OK, MessageBoxIcon.Information)
  67.             Dim trads As New Thread(AddressOf GetAnnounces)
  68.             trads.Start()
  69.         Else
  70.             MessageBox.Show("خطأ في اسم الستخدم او كلمة المرور")
  71.             TextBox1.ReadOnly = False
  72.             TextBox2.ReadOnly = False
  73.             Button1.Enabled = True
  74.         End If
  75.  
  76.     End Sub
  77.  
  78.     Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  79.         CheckForIllegalCrossThreadCalls = False
  80.     End Sub
  81.  
  82.     Private Sub GetAnnounces()
  83.         Dim wc As New WebClient() With {.Encoding = Encoding.Default}
  84.         Dim MC As MatchCollection = Regex.Matches(wc.DownloadString("http://haraj.com.sa/users/" & TextBox1.Text), "(?<=<tr ><td  >).*?(?=</td>)", RegexOptions.IgnoreCase)
  85.         For i = 0 To MC.Count - 1
  86.             ListBox1.Items.Add(MC(i).Value)
  87.         Next
  88.         If MC.Count > 0 Then
  89.             MessageBox.Show("تم جلب ارقام الاعلانات بنجاح", "تم بنجاح", MessageBoxButtons.OK, MessageBoxIcon.Information)
  90.         Else
  91.             MessageBox.Show("هذا الحساب لا يحتوى على اعلانات", "لا يوجد اعلانات", MessageBoxButtons.OK, MessageBoxIcon.Warning)
  92.  
  93.         End If
  94.    End Sub
  95.     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  96.         MessageBox.Show("جارى تسجيل الدخول .. يرجى الانتظار قليلًا", "جارى الدخول", MessageBoxButtons.OK, MessageBoxIcon.Information)
  97.         TextBox1.ReadOnly = True
  98.         TextBox2.ReadOnly = True
  99.         Button1.Enabled = False
  100.         Dim tr As New Thread(Sub() LoginAndUpdate(TextBox1.Text, TextBox2.Text))
  101.         tr.Start()
  102.     End Sub
  103.  
  104.     Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
  105.         For i = 0 To ListBox1.Items.Count
  106.             MsgBox(i)
  107.             Dim trUpdate As New Thread(Sub() UpdateAnnounce(ListBox1.Items(i).ToString()))
  108.             trUpdate.Start()
  109.             Do While trUpdate.IsAlive
  110.                 Application.DoEvents()
  111.             Loop
  112.         Next
  113.     End Sub
  114. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement