예제 #1
0
        private void menuItem_capopen_Click(object sender, System.EventArgs e)
        {
            string capFileName = "";
            captureFromFile = true;
            this.Text = "DICOM Network Analyzer";
            OpenFileDialog theOpenFileDialog = new OpenFileDialog();

            theOpenFileDialog.Filter = "Capture files(*.cap)|*.cap|Pcap Capture files(*.pcap)|*.pcap";
            theOpenFileDialog.Multiselect = false;
            theOpenFileDialog.Title = "Load a capture file";

            if (theOpenFileDialog.ShowDialog () == DialogResult.OK)
            {
                capFileName = theOpenFileDialog.FileName;
                this.Text = string.Format("DICOM Network Analyzer- Reading {0}", capFileName);

                //Create the directory for storing PDUs written in files
                CurrentBaseFileName = string.Format(@"{0}{1:yyyyMMdd_HHmmss}",resultDirectoryname,DateTime.Now);
                try
                {
                    Directory.CreateDirectory(CurrentBaseFileName);
                }
                catch (System.UnauthorizedAccessException)
                {
                    string msg = "Please check authorization and log-in with Administrator previlages.";
                    MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                CurrentBaseFileName += @"\";
                textLog = File.AppendText(CurrentBaseFileName + "Main.log");
                start = DateTime.Now;

                activityLogFileName = CurrentBaseFileName + "Activity.log";
                activityLog = File.AppendText(activityLogFileName);

                // Clear the activity logging, tabs & connection list
                analysisDlg.ClearLogging();
                comboBoxConnections.Items.Clear();
                dicom.ConnectionsList.Clear();
                comboBoxConnections.Enabled = false;
                HideTabs();

                //Disable Read PDUs button
                ReadCapture.Enabled = false;
                menuItem_capopen.Enabled = false;
                Explore.Visible = true;
                //CleanUp.Enabled = true;
                CleanUp.ToolTipText = "Auto Clean up enabled";

                dicom.BaseFileName = CurrentBaseFileName;

                try
                {
                    // Start the TCP parser thread
                    tcp.TCPStartAnalyse();
                    tcp.analysisFromCapFile = true;

                    Cursor.Current = Cursors.WaitCursor;

                    // Create WinPcap object instance for receieving TCP/IP packets
                    // from the capture file and subscribe for the error event.
                    capFileSniffer = new WinPCapObject(this, capFileName, tcp);
                    //capFileSniffer = new SnifferObject(this, capFileName, tcp);
                    capFileSniffer.Error += new Sniffer.ErrorEvent(ErrorHandler);
                    capFileSniffer.DataReceived += new Sniffer.DataReceivedEvent(tcp.AddPacket);
                    capFileSniffer.Start();
                }
                catch (Exception except)
                {
                    string msg = string.Format("Error:{0}\n", except.Message);
                    MessageBox.Show(this, msg, "Error",MessageBoxButtons.OK, MessageBoxIcon.Error );
                    tcp.TCPStopAnalyse();
                    menuItem_capopen.Enabled = true;
                    ReadCapture.Enabled = true;
                    comboBoxConnections.Enabled = true;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Event Handler for loading of main DICOM Sniffer form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DICOMSniffer_Load(object sender, System.EventArgs e)
        {
            // Create DICOM analyzer object instance for analyzing all DICOM PDUs
            // and subscribe for the logging event.
            dicom = new DICOMAnalyser(this);
            dicom.Output += new DICOMAnalyser.OutputEvent(OutputHandler);

            // Create TCP layer object instance for parsing TCP/IP packets and filtering
            // DICOM packets and subscribe for the events passing the DICOM packets to
            // upper DICOM layer
            tcp = new TCPParser();
            tcp.FragmentAdded += new TCPParser.FragmentAddedEvent(dicom.ReceiveTCPData);
            tcp.EndOfStream += new TCPParser.EndOfStreamEvent(dicom.EndOfStream);
            tcp.Error += new TCPParser.ErrorEvent(ErrorHandler);

            // Create low level sniffer object instance for sniffing TCP/IP packets
            // from the network and subscribe for the error event.
            sniffer = new SnifferObject();
            sniffer.Error += new Sniffer.ErrorEvent(ErrorHandler);
            sniffer.DataReceived += new Sniffer.DataReceivedEvent(tcp.AddPacket);

            try
            {
                // Get the list of network adapters(drivers) from the current machine
                string[] descriptions = sniffer.AdapterDescriptions;
                string[] names = sniffer.AdapterNames;

                for (int i = 0; i < descriptions.Length; i++)
                {
                    String desc = descriptions[i].Replace("\0", "");
                    String name = names[i].Replace("\0", "");
                    adapterList.Items.Add(name + " (" + desc + ")");
                }
            }
            catch (Exception except)
            {
                string msg = string.Format("Error:{0}\n", except.Message);
                MessageBox.Show(this, "Please install the WinPcap4.x.\n" +msg, "Error",MessageBoxButtons.OK, MessageBoxIcon.Error );
                this.Close();
                return;
            }

            // Select the first adapter from the list by default
            if(adapterList.Items.Count != 0)
            {
                selectedAdapter.Text = adapterList.Items[0].ToString();
                adapterList.SelectedIndex = 0;
            }
            else
            {
                string msg = "No network adapter(driver) detected on the machine.\nPlease install the WinPcap4.x.\r\n";
                MessageBox.Show(this, msg, "Warning",MessageBoxButtons.OK, MessageBoxIcon.Warning );
                this.Close();
                return;
            }

            // Load the Dvtk Sniffer session and
            try
            {
                dvtkSnifferSession = SnifferSession.LoadFromFile(Application.StartupPath + @"\NetworkAnalyzer.ses");

                // Get the results directory
                if(dvtkSnifferSession != null)
                {
                    resultDirectoryname = dvtkSnifferSession.ResultsRootDirectory;
                }
            }
            catch (Exception except)
            {
                string msg = string.Format("Error in loading Network Analyzer session file\r\n due to {0}",except.Message);
                MessageBox.Show(this, msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
                return;
            }

            //Get the IP Address of the current machine
            try
            {
                string strHostName = Dns.GetHostName();
                IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
                IPAddress [] addr = ipEntry.AddressList;
                if(addr != null)
                {
                    foreach (IPAddress address in addr)
                    {
                        if (address.AddressFamily.ToString() == ProtocolFamily.InterNetwork.ToString())
                        {
                            ipAddress1.Text = address.ToString();
                        }
                    }
                }
            }
            catch (SocketException)
            {
                //Do nothing in case of no specific DNS configuration present
            }

            //Default setting for all toolbar buttons & menuitems
            menuItemAnalysisMode.Checked = false;
            menuItem_capopen.Visible = false;
            ReadCapture.Visible = false;
            Explore.Visible = false;
            Error.Visible = false;
            Warning.Visible = false;
            Backward.Visible = false;
            Forward.Visible = false;
            menuItemView.Visible = false;
            menuItemShowResult.Enabled = false;
            tabControlSniffer.Controls.Remove(tabAssoOverview);
            tabControlSniffer.Controls.Remove(tabPDUsOverview);
            tabControlSniffer.Controls.Remove(tabSummaryValidationResults);
            tabControlSniffer.Controls.Remove(tabDetailValidationResults);

            menuItemConfig.Visible = true;
            menuItemSaveResultsAs.Visible = true;
            menuItem_capaspdus.Visible = true;
            menuItem_capaspdus.Enabled = false;
            menuItemCap.Visible = true;

            SaveConfig.Visible = true;
            SaveResultAs.Visible = true;
            CaptureButton.Visible = true;
        }