1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
Public Class Form1 Public WithEvents MyClient As System.Net.WebClient Public TotalWorkingThreads As Integer = 0 Public TotalTags As Integer = 0 Public gExtractedLinks(50000) As String Private Sub SpiderThePageCache(ByVal Webpage As String) MyClient = New System.Net.WebClient Dim WebpageDocument As String = MyClient.DownloadString(Webpage) Dim AhrefIndex As Integer = 0 Dim ExtractedLink As String Dim ExtractedLinks(5000) As String Dim Flag As Boolean = False While True Flag = False AhrefIndex = WebpageDocument.IndexOf("a href", AhrefIndex) If AhrefIndex = -1 Then Exit While If WebpageDocument.Chars(AhrefIndex + 8) = "#" Then AhrefIndex += 8 Continue While End If ExtractedLink = vbNullString For i = (AhrefIndex + 8) To WebpageDocument.Length - 1 ' (AhrefIndex + 25) If WebpageDocument.Chars(i) = Chr(34) Then Exit For ExtractedLink &= WebpageDocument.Chars(i) Next Debug.WriteLine(AhrefIndex & " : " & ExtractedLink) For i = 0 To ExtractedLinks.Length If ExtractedLinks(i) = ExtractedLink Then Flag = True Exit For End If If ExtractedLinks(i) = Nothing Then Exit For End If Next If Flag = False Then For i = 0 To ExtractedLinks.Length If ExtractedLinks(i) = Nothing Then ExtractedLinks(i) = ExtractedLink Exit For End If Next End If AhrefIndex += 8 End While End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'SpiderThePage("Http://WebsiteToAudit/") Dim SpiderClass = New SpideringThreads SpiderClass.CallBack = Me SpiderClass.Webpage = "Http://Ikenet" Dim T = New Threading.Thread(AddressOf SpiderClass.SpiderMainPageWithThreads) T.IsBackground = False T.Priority = Threading.ThreadPriority.Highest T.Start() End Sub Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub End Class Class SpideringThreads Public CallBack As Form1 Public WithEvents MyClient As System.Net.WebClient Delegate Sub MyDelPtr() Public Webpage As String Enum Marker AHref = 1 AutoComplete = 2 Three = 3 End Enum Public Sub SpiderMainPageWithThreads() MyClient = New System.Net.WebClient Dim WebpageDocument As String Try WebpageDocument = MyClient.DownloadString(Webpage) Catch ex As Exception 'ListBox2.Items.Add(Webpage) Dim MyGUIClass = New GUIThreads MyGUIClass.Data = Webpage CallBack.Invoke(New MyDelPtr(AddressOf MyGUIClass.Listbox2Add)) 'Invoke on main thread Exit Sub End Try If InStr(WebpageDocument, "PASSWORD=", CompareMethod.Text) > 0 Or InStr(WebpageDocument, "developer for debugging", CompareMethod.Text) > 0 Then 'ListBox1.Items.Add(Webpage) Dim MyGUIClass = New GUIThreads MyGUIClass.Data = Webpage CallBack.Invoke(New MyDelPtr(AddressOf MyGUIClass.Listbox1Add)) 'Invoke on main thread End If Dim MasterIndex As Integer = 0 Dim ExtractedLink As String Dim Marker1, Marker2 As Integer Dim MarkerPath As Marker = 0 While True Marker1 = WebpageDocument.IndexOf("a href=""", MasterIndex) Marker2 = WebpageDocument.IndexOf(".autocomplete(", MasterIndex) If Marker1 = -1 And Marker2 = -1 Then Exit While End If If Marker1 = -1 Then MasterIndex = Marker2 MarkerPath = Marker.AutoComplete ElseIf Marker2 = -1 Then MasterIndex = Marker1 MarkerPath = Marker.AHref Else If Marker1 > Marker2 And Marker2 <> -1 Then MasterIndex = Marker2 MarkerPath = Marker.AutoComplete ElseIf Marker2 > Marker1 And Marker1 <> -1 Then MasterIndex = Marker1 MarkerPath = Marker.AHref End If End If Dim JumpInteger As Integer = 0 Select Case MarkerPath Case Marker.AHref JumpInteger = 8 Case Marker.AutoComplete JumpInteger = 15 Case Marker.Three Debug.WriteLine("Marker 3") Case Else Debug.WriteLine("Unknown value") End Select If WebpageDocument.Chars(MasterIndex + JumpInteger) = "#" Then MasterIndex += JumpInteger Continue While End If ExtractedLink = vbNullString For i = (MasterIndex + JumpInteger) To WebpageDocument.Length - 1 ' (AhrefIndex + 25) If WebpageDocument.Chars(i) = Chr(34) Then If ExtractedLink = Nothing Then MasterIndex += JumpInteger Continue While End If Exit For End If ExtractedLink &= WebpageDocument.Chars(i) Next Debug.WriteLine(MasterIndex & " : " & ExtractedLink) If Not ExtractedLink.StartsWith("HTTP", True, Nothing) Then ExtractedLink = "Http://Ikenet/" & ExtractedLink Else If Not ExtractedLink.StartsWith("Http://Ikenet/", True, Nothing) Or Not ExtractedLink.StartsWith("Https://Ikenet/", True, Nothing) Then Debug.WriteLine("NOT IKENET") MasterIndex += 8 Continue While End If End If If AddStringToGArray(ExtractedLink) Then 'SpiderThePage(ExtractedLink) Dim MyTotalClass = New GUIThreads CallBack.Invoke(New MyDelPtr(AddressOf MyTotalClass.AddWorkingThreads)) CallBack.Invoke(New MyDelPtr(AddressOf MyTotalClass.AddTotal)) 'Invoke on main thread Dim Spider = New SpideringThreads Spider.Webpage = ExtractedLink Spider.CallBack = CallBack Dim T As New Threading.Thread(AddressOf Spider.SpiderNewPageWithThreads) T.Start() Else Debug.WriteLine("Skipped Dubbed: " & ExtractedLink) End If MasterIndex += JumpInteger End While End Sub Public Sub SpiderNewPageWithThreads() MyClient = New System.Net.WebClient Dim WebpageDocument As String Try WebpageDocument = MyClient.DownloadString(Webpage) Catch ex As Exception 'ListBox2.Items.Add(Webpage) Dim MyGUIClass = New GUIThreads If ex.Message = "The remote server returned an error: (500) Internal Server Error." Then MyGUIClass.Data = Webpage CallBack.Invoke(New MyDelPtr(AddressOf MyGUIClass.Listbox1Add)) 'Invoke on main thread Exit Sub End If MyGUIClass.Data = Webpage CallBack.Invoke(New MyDelPtr(AddressOf MyGUIClass.Listbox2Add)) 'Invoke on main thread Exit Sub End Try If InStr(WebpageDocument, "PASSWORD=", CompareMethod.Text) > 0 Or InStr(WebpageDocument, "developer for debugging", CompareMethod.Text) > 0 Then 'ListBox1.Items.Add(Webpage) Dim MyGUIClass = New GUIThreads MyGUIClass.Data = Webpage CallBack.Invoke(New MyDelPtr(AddressOf MyGUIClass.Listbox1Add)) 'Invoke on main thread End If Dim AhrefIndex As Integer = 0 Dim ExtractedLink As String While True AhrefIndex = WebpageDocument.IndexOf("a href", AhrefIndex) If AhrefIndex = -1 Then Exit While If WebpageDocument.Chars(AhrefIndex + 8) = "#" Then AhrefIndex += 8 Continue While End If ExtractedLink = vbNullString For i = (AhrefIndex + 8) To WebpageDocument.Length - 1 ' (AhrefIndex + 25) If WebpageDocument.Chars(i) = Chr(34) Then If ExtractedLink = Nothing Then AhrefIndex += 8 Continue While End If Exit For End If ExtractedLink &= WebpageDocument.Chars(i) Next Debug.WriteLine(AhrefIndex & " : " & ExtractedLink) If Not ExtractedLink.StartsWith("HTTP", True, Nothing) Then ExtractedLink = "Http://Ikenet/" & ExtractedLink Else If Not ExtractedLink.StartsWith("Http://Ikenet/", True, Nothing) Or Not ExtractedLink.StartsWith("Https://Ikenet/", True, Nothing) Then Debug.WriteLine("NOT IKENET") AhrefIndex += 8 Continue While End If End If If AddStringToGArray(ExtractedLink) Then Dim MyTotalClass = New GUIThreads CallBack.Invoke(New MyDelPtr(AddressOf MyTotalClass.AddTotal)) 'Invoke on main thread SpiderThePage(ExtractedLink) Else Debug.WriteLine("Skipped Dubbed: " & ExtractedLink) End If AhrefIndex += 8 End While End Sub Public Sub SpiderThePage(ByVal WebSite As String) MyClient = New System.Net.WebClient Dim WebSiteDocument As String Try WebSiteDocument = MyClient.DownloadString(WebSite) Catch ex As Exception 'ListBox2.Items.Add(WebSite) Dim MyGUIClass = New GUIThreads MyGUIClass.Data = WebSite CallBack.Invoke(New MyDelPtr(AddressOf MyGUIClass.Listbox2Add)) 'Invoke on main thread Exit Sub End Try If InStr(WebSiteDocument, "PASSWORD=", CompareMethod.Text) > 0 Or InStr(WebSiteDocument, "developer for debugging", CompareMethod.Text) > 0 Then 'ListBox1.Items.Add(WebSite) Dim MyGUIClass = New GUIThreads MyGUIClass.Data = WebSite CallBack.Invoke(New MyDelPtr(AddressOf MyGUIClass.Listbox1Add)) 'Invoke on main thread End If Dim AhrefIndex As Integer = 0 Dim ExtractedLink As String While True AhrefIndex = WebSiteDocument.IndexOf("a href", AhrefIndex) If AhrefIndex = -1 Then Exit While If WebSiteDocument.Chars(AhrefIndex + 8) = "#" Then AhrefIndex += 8 Continue While End If ExtractedLink = vbNullString For i = (AhrefIndex + 8) To WebSiteDocument.Length - 1 ' (AhrefIndex + 25) If WebSiteDocument.Chars(i) = Chr(34) Then If ExtractedLink = Nothing Then AhrefIndex += 8 Continue While End If Exit For End If ExtractedLink &= WebSiteDocument.Chars(i) Next Debug.WriteLine(AhrefIndex & " : " & ExtractedLink) If Not ExtractedLink.StartsWith("HTTP", True, Nothing) Then ExtractedLink = WebSite & ExtractedLink Else If Not ExtractedLink.StartsWith("Http://Ikenet/", True, Nothing) Or Not ExtractedLink.StartsWith("Https://Ikenet/", True, Nothing) Then Debug.WriteLine("NOT IKENET") AhrefIndex += 8 Continue While End If End If If AddStringToGArray(ExtractedLink) Then Dim MyTotalClass = New GUIThreads CallBack.Invoke(New MyDelPtr(AddressOf MyTotalClass.AddTotal)) 'Invoke on main thread SpiderThePage(ExtractedLink) Else Debug.WriteLine("Skipped Dubbed: " & ExtractedLink) End If AhrefIndex += 8 End While End Sub Private Function AddStringToGArray(ByVal Webpage As String) As Boolean For i = 0 To CallBack.gExtractedLinks.Length If CallBack.gExtractedLinks(i) = Webpage Then Return False Exit For End If If CallBack.gExtractedLinks(i) = Nothing Then CallBack.gExtractedLinks(i) = Webpage Return True End If Next Return True End Function End Class Class GUIThreads Public Data As String Public Sub Listbox1Add() Form1.ListBox1.Items.Add(Data) End Sub Public Sub Listbox2Add() Form1.ListBox2.Items.Add(Data) End Sub Public Sub AddTotal() Form1.TotalTags += 1 Form1.Text = "Working Threads : " & Form1.TotalWorkingThreads & "Total Spidered: " & Form1.TotalTags End Sub Public Sub AddWorkingThreads() Form1.TotalWorkingThreads += 1 Form1.Text = "Working Threads : " & Form1.TotalWorkingThreads & "Total Spidered: " & Form1.TotalTags End Sub End Class |