private async void scanButton_Click(object sender, EventArgs e) { buildScanList(); if (scanner.Length > 0 && saveFileDialog1.ShowDialog() == DialogResult.OK) { progressBar1.Maximum = scanner.Length + 1; IPRangeWriter writer = new IPRangeWriter(scanner); writer.createTempFile(saveFileDialog1.FileName); Task scan = scanner.buildIPTableAsync(updateProgressBar, updateIPLabel); await scan; writer.writeIPTable(saveFileDialog1.FileName); writer.writeHTMLTable(saveFileDialog1.FileName); updateProgressBar(0); currentIPLabel.Text = "Current IP: N/A"; currentIPLabel.Refresh(); MessageBox.Show("Scan complete!\nNumber of " + numberOfIPs.Text); } else if (scanner.Length <= 0) { MessageBox.Show("Invalid Range"); } }
// This method tries to access and read index.html at a given // IP Address's root directory private void readHTML(IPAddress address) { Uri currURI = new Uri("http://" + address.ToString()); WebRequest request = WebRequest.Create(currURI); request.Timeout = timeout; string currString; try { // Get the response. HttpWebResponse response = (HttpWebResponse)request.GetResponse(); // Display the status. Console.WriteLine(response.StatusDescription); // Get the stream containing content returned by the server. Stream dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. currString = reader.ReadToEnd(); // Cleanup the streams and the response. reader.Close(); dataStream.Close(); response.Close(); ipTable.Enqueue(string.Copy(address.ToString())); htmlTable.Enqueue(string.Copy(currString)); // If tempfile isn't null, then append the current IP to it if (tempfile != null) { IPRangeWriter.appendTempIPTable(address, tempfile); } } catch (WebException) { } }