ibennz

Untitled

Nov 21st, 2013
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 4.62 KB | None | 0 0
  1. Imports System.Net
  2. Imports System.IO
  3. Imports System.Threading
  4. Imports System.ComponentModel
  5. Imports System.Collections.Specialized
  6.  
  7. Public Class Scanner
  8.     Public Shared Event Logged(success As Boolean)
  9.     Private Shared MainCookie As New CookieContainer
  10.     Private Shared Operation As AsyncOperation
  11.     Public Shared Sub Login(ByVal key As String)
  12.         Operation = AsyncOperationManager.CreateOperation(Nothing)
  13.         key = key.Insert(0, "key=")
  14.         Dim mKey() As Byte = System.Text.Encoding.UTF8.GetBytes(key)
  15.         Dim Tr As New Thread(New ParameterizedThreadStart(Sub() DoLogin(mKey)))
  16.         Tr.SetApartmentState(ApartmentState.STA)
  17.         Tr.Start()
  18.  
  19.  
  20.     End Sub
  21.     Public Shared Sub Scan(ByVal scanfilepath As String)
  22.         Dim Tr As New Thread(New ParameterizedThreadStart(Sub() DoScan(scanfilepath)))
  23.         Tr.SetApartmentState(ApartmentState.STA)
  24.         Tr.Start()
  25.     End Sub
  26.  
  27.     Private Shared Sub DoScan(ByVal scanfilepath As String)
  28.  
  29.         Dim S As New System.Text.StringBuilder
  30.         Dim B As String = "-----------------------------" & Now.Ticks
  31.        
  32.  
  33.  
  34.         Dim FileName As String = IO.Path.GetFileName(scanfilepath)
  35.         S.AppendLine(B)
  36.         S.AppendLine("Content-Disposition: form-data; name=""file""; filename=""" & FileName & """")
  37.         S.AppendLine("Content-Type: application/octet-stream")
  38.         S.AppendLine()
  39.  
  40.         Dim sParams As New System.Text.StringBuilder
  41.  
  42.         Dim params As New NameValueCollection
  43.         params.Add("submit", "Scan File")
  44.  
  45.         For Each E As String In params.Keys
  46.             sParams.AppendLine(B)
  47.             sParams.AppendLine("Content-Disposition: form-data; name=""" & E & """")
  48.             sParams.AppendLine()
  49.             sParams.AppendLine(params(E))
  50.         Next
  51.  
  52.         Dim mFileBytes() As Byte = IO.File.ReadAllBytes(scanfilepath)
  53.         Dim Header As Byte() = System.Text.Encoding.UTF8.GetBytes(S.ToString)
  54.         Dim Footer As Byte() = System.Text.Encoding.UTF8.GetBytes(Environment.NewLine & B & "--")
  55.         Dim middle As Byte() = System.Text.Encoding.UTF8.GetBytes(sParams.ToString)
  56.      
  57.         Dim wc As HttpWebRequest = DirectCast(WebRequest.Create("http://nodistribute.com/scan/"), HttpWebRequest)
  58.         wc.Method = "POST"
  59.         wc.Referer = "http://nodistribute.com/"
  60.         wc.KeepAlive = True
  61.         wc.Timeout = 600000
  62.         wc.ReadWriteTimeout = 20000
  63.         wc.CookieContainer = MainCookie
  64.         wc.AllowAutoRedirect = True
  65.         wc.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0"
  66.         wc.ContentLength = Header.Length + mFileBytes.Length + Footer.Length + middle.Length
  67.         wc.ContentType = "Content-Type: multipart/form-data; boundary=" & B.Substring(2)
  68.  
  69.  
  70.         Dim mStream As Stream = wc.GetRequestStream()
  71.         mStream.Write(Header, 0, Header.Length)
  72.         mStream.Write(mFileBytes, 0, mFileBytes.Length)
  73.         mStream.Write(middle, 0, middle.Length)
  74.         mStream.Write(Footer, 0, Footer.Length)
  75.         mStream.Close()
  76.  
  77.  
  78.         Dim U As WebResponse = wc.GetResponse()
  79.         Dim O As Stream = U.GetResponseStream()
  80.  
  81.         Dim SR As New StreamReader(O)
  82.         Dim HTML As String = SR.ReadToEnd()
  83.         SR.Close()
  84.  
  85.         IO.File.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\1.html", HTML)
  86.     End Sub
  87.  
  88.  
  89.     Private Shared Sub DoLogin(ByVal mkey() As Byte)
  90.  
  91.         Dim wc As HttpWebRequest = DirectCast(WebRequest.Create("http://nodistribute.com/login/"), HttpWebRequest)
  92.         Dim tmpCookie As New CookieContainer
  93.         wc.Method = "POST"
  94.         wc.Referer = "http://nodistribute.com/login/"
  95.         wc.KeepAlive = True
  96.         wc.Timeout = 600000
  97.         wc.ReadWriteTimeout = 20000
  98.         wc.CookieContainer = tmpCookie
  99.         wc.AllowAutoRedirect = True
  100.         wc.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0"
  101.         wc.ContentLength = mkey.Length
  102.         wc.ContentType = "application/x-www-form-urlencoded"
  103.  
  104.         Dim W As Stream = wc.GetRequestStream()
  105.         W.Write(mkey, 0, mkey.Length)
  106.         W.Close()
  107.  
  108.  
  109.         Dim rep As WebResponse = wc.GetResponse()
  110.         Dim mStream As Stream = rep.GetResponseStream()
  111.  
  112.         Dim SR As New StreamReader(mStream)
  113.         Dim HTML As String = SR.ReadToEnd()
  114.         SR.Close()
  115.  
  116.         MainCookie = tmpCookie
  117.  
  118.         If HTML.Contains("Login successful") Then
  119.             Operation.Post(Sub() RaiseEvent Logged(True), Nothing)
  120.         Else
  121.             Operation.Post(Sub() RaiseEvent Logged(False), Nothing)
  122.         End If
  123.  
  124.     End Sub
  125. End Class
Advertisement
Add Comment
Please, Sign In to add comment