Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.Net
- Imports System.IO
- Imports System.Threading
- Imports System.ComponentModel
- Imports System.Collections.Specialized
- Public Class Scanner
- Public Shared Event Logged(success As Boolean)
- Private Shared MainCookie As New CookieContainer
- Private Shared Operation As AsyncOperation
- Public Shared Sub Login(ByVal key As String)
- Operation = AsyncOperationManager.CreateOperation(Nothing)
- key = key.Insert(0, "key=")
- Dim mKey() As Byte = System.Text.Encoding.UTF8.GetBytes(key)
- Dim Tr As New Thread(New ParameterizedThreadStart(Sub() DoLogin(mKey)))
- Tr.SetApartmentState(ApartmentState.STA)
- Tr.Start()
- End Sub
- Public Shared Sub Scan(ByVal scanfilepath As String)
- Dim Tr As New Thread(New ParameterizedThreadStart(Sub() DoScan(scanfilepath)))
- Tr.SetApartmentState(ApartmentState.STA)
- Tr.Start()
- End Sub
- Private Shared Sub DoScan(ByVal scanfilepath As String)
- Dim S As New System.Text.StringBuilder
- Dim B As String = "-----------------------------" & Now.Ticks
- Dim FileName As String = IO.Path.GetFileName(scanfilepath)
- S.AppendLine(B)
- S.AppendLine("Content-Disposition: form-data; name=""file""; filename=""" & FileName & """")
- S.AppendLine("Content-Type: application/octet-stream")
- S.AppendLine()
- Dim sParams As New System.Text.StringBuilder
- Dim params As New NameValueCollection
- params.Add("submit", "Scan File")
- For Each E As String In params.Keys
- sParams.AppendLine(B)
- sParams.AppendLine("Content-Disposition: form-data; name=""" & E & """")
- sParams.AppendLine()
- sParams.AppendLine(params(E))
- Next
- Dim mFileBytes() As Byte = IO.File.ReadAllBytes(scanfilepath)
- Dim Header As Byte() = System.Text.Encoding.UTF8.GetBytes(S.ToString)
- Dim Footer As Byte() = System.Text.Encoding.UTF8.GetBytes(Environment.NewLine & B & "--")
- Dim middle As Byte() = System.Text.Encoding.UTF8.GetBytes(sParams.ToString)
- Dim wc As HttpWebRequest = DirectCast(WebRequest.Create("http://nodistribute.com/scan/"), HttpWebRequest)
- wc.Method = "POST"
- wc.Referer = "http://nodistribute.com/"
- wc.KeepAlive = True
- wc.Timeout = 600000
- wc.ReadWriteTimeout = 20000
- wc.CookieContainer = MainCookie
- wc.AllowAutoRedirect = True
- wc.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0"
- wc.ContentLength = Header.Length + mFileBytes.Length + Footer.Length + middle.Length
- wc.ContentType = "Content-Type: multipart/form-data; boundary=" & B.Substring(2)
- Dim mStream As Stream = wc.GetRequestStream()
- mStream.Write(Header, 0, Header.Length)
- mStream.Write(mFileBytes, 0, mFileBytes.Length)
- mStream.Write(middle, 0, middle.Length)
- mStream.Write(Footer, 0, Footer.Length)
- mStream.Close()
- Dim U As WebResponse = wc.GetResponse()
- Dim O As Stream = U.GetResponseStream()
- Dim SR As New StreamReader(O)
- Dim HTML As String = SR.ReadToEnd()
- SR.Close()
- IO.File.WriteAllText(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) & "\1.html", HTML)
- End Sub
- Private Shared Sub DoLogin(ByVal mkey() As Byte)
- Dim wc As HttpWebRequest = DirectCast(WebRequest.Create("http://nodistribute.com/login/"), HttpWebRequest)
- Dim tmpCookie As New CookieContainer
- wc.Method = "POST"
- wc.Referer = "http://nodistribute.com/login/"
- wc.KeepAlive = True
- wc.Timeout = 600000
- wc.ReadWriteTimeout = 20000
- wc.CookieContainer = tmpCookie
- wc.AllowAutoRedirect = True
- wc.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0"
- wc.ContentLength = mkey.Length
- wc.ContentType = "application/x-www-form-urlencoded"
- Dim W As Stream = wc.GetRequestStream()
- W.Write(mkey, 0, mkey.Length)
- W.Close()
- Dim rep As WebResponse = wc.GetResponse()
- Dim mStream As Stream = rep.GetResponseStream()
- Dim SR As New StreamReader(mStream)
- Dim HTML As String = SR.ReadToEnd()
- SR.Close()
- MainCookie = tmpCookie
- If HTML.Contains("Login successful") Then
- Operation.Post(Sub() RaiseEvent Logged(True), Nothing)
- Else
- Operation.Post(Sub() RaiseEvent Logged(False), Nothing)
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment