private void AcuRiteSetupToolStripMenuItem_Click_1(object sender, EventArgs e) { try { frmSetup setup = new frmSetup(); setup.ShowDialog(); } catch (Exception ex) { if (ex.Message.IndexOf("pcap", StringComparison.OrdinalIgnoreCase) == 0) { MessageBox.Show("ERROR: " + ex.Message + System.Environment.NewLine + System.Environment.NewLine + "Please go to http://www.winpcap.org , download WinPcap, and install it."); } else { MessageBox.Show("ERROR: " + ex.Message); } } }
private void btnStart_Click(object sender, EventArgs e) { if (Properties.Settings.Default.networkDevice.Length > 0) { txtOutput.Text = waitMessage; txtOutput.Refresh(); lblWuStationID.Text = Properties.Settings.Default.wuStation; lblWbStationID.Text = Properties.Settings.Default.wbStation; lblPwsStationID.Text = Properties.Settings.Default.pwsStation; lblAweatherStationID.Text = Properties.Settings.Default.awStation; pbarProgressBar1.Value = 5; if (BackgroundWorker1.IsBusy == false) { BackgroundWorker1.RunWorkerAsync(); } } else { try { frmSetup setup = new frmSetup(); setup.ShowDialog(); } catch (Exception ex) { if (ex.Message.IndexOf("pcap", StringComparison.OrdinalIgnoreCase) == 0) { MessageBox.Show("ERROR: " + ex.Message + System.Environment.NewLine + System.Environment.NewLine + "Please go to http://www.winpcap.org , download WinPcap, and install it."); } else { MessageBox.Show("ERROR: " + ex.Message); } } } }
private void BackgroundWorker1_DoWork_1(object sender, DoWorkEventArgs e) { if (string.IsNullOrEmpty(Properties.Settings.Default.networkDevice)) { BackgroundWorker1.Dispose(); pbarProgressBar1.Value = 0; this.Invoke(new MethodInvoker(() => txtOutput.Text = txtOutput.Text.Replace(waitMessage, ""))); frmSetup setup = new frmSetup(); setup.ShowDialog(); } try { int deviceNumberToUse = 0; IList <LivePacketDevice> allDevices = LivePacketDevice.AllLocalMachine; int i = 0; while (i != allDevices.Count) { LivePacketDevice device = allDevices[i]; if (Properties.Settings.Default.networkDevice.IndexOf(device.Name.ToString(), StringComparison.OrdinalIgnoreCase) == 0) { deviceNumberToUse = i; } i += 1; } PacketDevice selectedDevice = allDevices[deviceNumberToUse]; try { // Open the device // portion of the packet to capture // 65536 guarantees that the whole packet will be captured on all the link layers // promiscuous mode using (communicator = selectedDevice.Open(65536, PacketDeviceOpenAttributes.NoCaptureLocal, 1000)) //using (PacketCommunicator communicator = selectedDevice.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000)) { // start the capture communicator.ReceivePackets(0, PacketHandler); } } catch (Exception ex) { this.Invoke(new MethodInvoker(() => txtOutput.Text = DateTime.Now + "\t" + "ERROR: " + ex.Message + System.Environment.NewLine + txtOutput.Text)); } } catch (System.InvalidOperationException ex) { if (ex.Message.IndexOf("pcap") == 0) { MessageBox.Show("ERROR: " + ex.Message + System.Environment.NewLine + System.Environment.NewLine + "Please go to http://www.winpcap.org , download WinPcap, and install it."); } else { MessageBox.Show("ERROR: " + ex.Message); } Close(); } catch (Exception ex) { MessageBox.Show("ERROR: " + ex.Message); Close(); } }