Imports System.Threading
Public Class Form1
Inherits System.Windows.Forms.Form
Dim LFile As String
Dim LFileSize As Int32 = 32767
Dim LineArray() As String
Dim NameArray() As String
Public nThreads As Int16 = 0
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents eLabel As System.Windows.Forms.Label
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Friend WithEvents txtIP As System.Windows.Forms.TextBox
Friend WithEvents cmbLocale As System.Windows.Forms.ComboBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
Me.eLabel = New System.Windows.Forms.Label()
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.txtIP = New System.Windows.Forms.TextBox()
Me.cmbLocale = New System.Windows.Forms.ComboBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.Button1 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'eLabel
'
Me.eLabel.Location = New System.Drawing.Point(0, 64)
Me.eLabel.Name = "eLabel"
Me.eLabel.Size = New System.Drawing.Size(336, 168)
Me.eLabel.TabIndex = 0
'
'Timer1
'
Me.Timer1.Interval = 500
'
'txtIP
'
Me.txtIP.Location = New System.Drawing.Point(96, 8)
Me.txtIP.Name = "txtIP"
Me.txtIP.Size = New System.Drawing.Size(120, 20)
Me.txtIP.TabIndex = 1
'
'cmbLocale
'
Me.cmbLocale.Location = New System.Drawing.Point(96, 32)
Me.cmbLocale.Name = "cmbLocale"
Me.cmbLocale.Size = New System.Drawing.Size(232, 21)
Me.cmbLocale.TabIndex = 2
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(8, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(80, 23)
Me.Label1.TabIndex = 3
Me.Label1.Text = "IP Address"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(8, 32)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(80, 16)
Me.Label2.TabIndex = 4
Me.Label2.Text = "Temp Locale"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(224, 8)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(104, 24)
Me.Button1.TabIndex = 5
Me.Button1.Text = "Start | Stop"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(336, 230)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1, Me.Label2, Me.Label1, Me.cmbLocale, Me.txtIP, Me.eLabel})
Me.Name = "Form1"
Me.Text = "Downloader"
Me.ResumeLayout(False)
End Sub
#End Region
Public Declare Function DeleteUrlCacheEntry Lib "Wininet.dll" _
Alias "DeleteUrlCacheEntryA" _
(ByVal lpszUrlName As String) As Long
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim theNet As New System.Net.WebClient()
Dim theDataBuffer As Byte()
Dim DLFile As String
Dim x As Int16
For x = 0 To 25
cmbLocale.Items.Add(Chr(x + 65) & ":\")
Next
theDataBuffer = theNet.DownloadData("http://" & txtIP.Text)
DLFile = System.Text.Encoding.ASCII.GetString(theDataBuffer)
LineArray = Split(DLFile, (Chr(10)))
NameArray = Split(DLFile, (Chr(10)))
For x = 0 To UBound(LineArray)
If (Len(Mid(LineArray(x), InStrRev(LineArray(x), "<td>") + 4)) < (Len(LineArray(x)) - 5)) AndAlso (InStrRev(NameArray(x), "</a>") > 0) Then
LineArray(x) = Mid(LineArray(x), InStrRev(LineArray(x), "<td>") + 4)
NameArray(x) = Mid(NameArray(x), InStrRev(NameArray(x), """>") + 2)
NameArray(x) = Mid(NameArray(x), 1, InStrRev(NameArray(x), "</a>") - 1)
If (LFileSize > Val(LineArray(x))) AndAlso (Val(LineArray(x)) > 1000) Then
LFileSize = LineArray(x)
LFile = NameArray(x)
End If
Else
LineArray(x) = ""
NameArray(x) = ""
End If
Next
End Sub
Private Sub Form1_Unload(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Try
Dim dlthd As DLThread = New DLThread(eLabel, cmbLocale, NameArray, txtIP)
Dim thd As Thread = New Thread(AddressOf dlthd.DoWork)
thd.Priority = ThreadPriority.BelowNormal
thd.Start()
Catch
End Try
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = Not Timer1.Enabled
End Sub
End Class
Public Class DLThread
Public Declare Function DeleteUrlCacheEntry Lib "Wininet.dll" _
Alias "DeleteUrlCacheEntryA" _
(ByVal lpszUrlName As String) As Long
Private ginLabel As Label
Private gcmbLocale As ComboBox
Private gNameArray As System.Array
Private gtxtIP As TextBox
Public Sub New(ByRef inLabel As Label, ByVal cmbLocale As ComboBox, ByVal NameArray As System.Array, ByVal txtIP As TextBox)
ginLabel = inLabel
gcmbLocale = cmbLocale
gNameArray = NameArray
gtxtIP = txtIP
End Sub
Public Sub DoWork()
Try
ginLabel.Text = ""
Randomize()
Dim theNet As New System.Net.WebClient()
Dim theFile As String = gcmbLocale.SelectedItem & "file." & Rnd() * 32767
Dim DLEntry As String = "http://" & gtxtIP.Text & "/" & gNameArray(Int(Rnd() * UBound(gNameArray)))
DeleteUrlCacheEntry(DLEntry)
theNet.DownloadFile(DLEntry, theFile)
Kill(theFile)
Catch ee As System.Net.WebException
ginLabel.Text = ee.ToString()
End Try
End Sub
End Class