Exemplo n.º 1
0
        /// <summary>
        /// The Method That Parse The NetStat Output
        /// And Returns A List Of Port Objects
        /// </summary>
        /// <returns>all port  list by prosses name and protocol</returns>
        public static OnGetNetStatPortsResponse OnGetNetStatPorts()
        {
            OnGetNetStatPortsResponse ROnGetNetStatPortsResponse = new OnGetNetStatPortsResponse();

            try
            {
                OnExecuteProcessResponse ExecuteResponse = _m_Process_Manager.OnExecuteProcess("netstat.exe", "-a -n -o", ProcessOutputType: _m_Child_Process.Enum_ProcessOutputType.Cmd, FullHide: false);

                string   Output      = ExecuteResponse.Output;
                string[] Connections = Regex.Split(Output, "\r\n");
                foreach (string Connection in Connections)
                {
                    string[] tokens = Regex.Split(Connection, "\\s+");
                    if (tokens.Length > 4 && (tokens[1].Equals("UDP") || tokens[1].Equals("TCP")))
                    {
                        OnGetNetStatPortsResponse.Connection connection = new OnGetNetStatPortsResponse.Connection();
                        string localAddress = Regex.Replace(tokens[2], @"\[(.*?)\]", "1.1.1.1");
                        connection.LocalAddress  = localAddress;
                        connection.Protocol      = localAddress.Contains("1.1.1.1") ? String.Format("{0}v6", tokens[1]) : String.Format("{0}v4", tokens[1]);
                        connection.RemoteAddress = tokens[3];
                        connection.Port          = localAddress.Split(':')[1];
                        connection.ProcessName   = tokens[1] == "UDP" ? LookupProcess(Convert.ToInt16(tokens[4])) : LookupProcess(Convert.ToInt16(tokens[5]));
                        ROnGetNetStatPortsResponse.Connections.Add(connection);
                    }
                }
            }
            catch (Exception ex)
            {
                ROnGetNetStatPortsResponse.Errors.AddErrorToErrorList(MethodBase.GetCurrentMethod().ToString(), ex.Message);
            }
            return(ROnGetNetStatPortsResponse);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        /// <param name="Command">The command.</param>
        /// <returns>json object.if successful return output of executed standard stdout else return error</returns>
        public static OnExecuteProcessResponse ExecuteCmd(string Command)
        {
            OnExecuteProcessResponse ROnExecuteProcessResponse = new OnExecuteProcessResponse();

            ROnExecuteProcessResponse.Target_Executable = Command;
            try {
                ROnExecuteProcessResponse = _m_Process_Manager.OnExecuteProcess("cmd.exe", Command, ProcessParametersType: _m_Child_Process.Enum_ProcessParametersType.Stdin, ProcessOutputType: _m_Child_Process.Enum_ProcessOutputType.Cmd);
            }catch (Exception ex)
            {
                ROnExecuteProcessResponse.Errors.AddErrorToErrorList(MethodBase.GetCurrentMethod().ToString(), ex.Message);
            }
            return(ROnExecuteProcessResponse);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Called when [system information].
        /// </summary>
        /// <returns>return OnGetSystemInformationResponse contain system information data of created nfo file</returns>
        public static OnGetSystemInformationResponse OnGetSystemInformation()
        {
            OnGetSystemInformationResponse ROnGetSystemInformationResponse = new OnGetSystemInformationResponse();

            try
            {
                OnExecuteProcessResponse Execute_msinfo32 = _m_Process_Manager.OnExecuteProcess("msinfo32.exe", "/nfo info.nfo", OutputFile: "info.nfo");
                ROnGetSystemInformationResponse.Output = Execute_msinfo32.Output;
            }
            catch (Exception ex)
            {
                ROnGetSystemInformationResponse.Errors.AddErrorToErrorList(MethodBase.GetCurrentMethod().ToString(), ex.Message);
            }
            return(ROnGetSystemInformationResponse);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Executes the child process.
        /// </summary>
        /// <param name="Target_Executable">The target executable.</param>
        /// <param name="Parametrs">The parametrs.</param>
        /// <param name="ProcessParametersType">Type of the process parameters.</param>
        /// <param name="NoWindow">if set to <c>true</c> [no window].</param>
        /// <param name="FullHide">if set to <c>true</c> [full hide].</param>
        /// <param name="ReturnOutput">if set to <c>true</c> [return output].</param>
        /// <param name="ProcessOutputType">Type of the process output.</param>
        /// <param name="OutputFile">The output file.</param>
        /// <returns></returns>
        public OnExecuteProcessResponse ExecuteChildProcess(string Target_Executable, string Parametrs, Enum_ProcessParametersType ProcessParametersType = Enum_ProcessParametersType.Argument, bool NoWindow = true, bool FullHide = true, bool ReturnOutput = true, Enum_ProcessOutputType ProcessOutputType = Enum_ProcessOutputType.File, string OutputFile = "output.txt")
        {
            OnExecuteProcessResponse ROnExecuteProcessResponse = new OnExecuteProcessResponse();

            ROnExecuteProcessResponse.Target_Executable = Target_Executable;

            //declare here for stop it after end of work on try or catch
            System.Timers.Timer timer_for_hide_window = null;
            try
            {
                ProcessStartInfo ExecutableStartInfo = new ProcessStartInfo();
                ExecutableStartInfo.FileName = Target_Executable;
                ExecutableStartInfo.RedirectStandardOutput = true;
                ExecutableStartInfo.RedirectStandardError  = true;
                ExecutableStartInfo.RedirectStandardInput  = true;
                ExecutableStartInfo.UseShellExecute        = false;
                if (ProcessParametersType == Enum_ProcessParametersType.Argument)
                {
                    ExecutableStartInfo.Arguments = Parametrs;
                }

                if (NoWindow)
                {
                    ExecutableStartInfo.CreateNoWindow = true;
                    ExecutableStartInfo.WindowStyle    = ProcessWindowStyle.Hidden;
                }


                Process ChildProcess = new Process();
                ChildProcess.StartInfo           = ExecutableStartInfo;
                ChildProcess.OutputDataReceived += ChildProcess_OutputDataReceived;
                ChildProcess.EnableRaisingEvents = true;
                ChildProcess.Start();
                ChildProcess.BeginOutputReadLine();
                ChildProcess.BeginErrorReadLine();

                if (FullHide)
                {
                    _ChildProcessId                = ChildProcess.Id;
                    timer_for_hide_window          = new System.Timers.Timer();
                    timer_for_hide_window.Interval = 1;
                    timer_for_hide_window.Elapsed += Timer_For_Hide_Window_Elapsed;
                    timer_for_hide_window.Start();
                }



                if (ProcessParametersType == Enum_ProcessParametersType.Stdin)
                {
                    ChildProcess.StandardInput.WriteLine(Parametrs);
                }



                if (ReturnOutput)
                {
                    if (ProcessOutputType == Enum_ProcessOutputType.Cmd)
                    {
                        ChildProcess.StandardInput.WriteLine("exit");
                    }

                    ChildProcess.WaitForExit();
                    ROnExecuteProcessResponse.Pid = ChildProcess.Id;

                    if (ProcessOutputType == Enum_ProcessOutputType.Cmd)
                    {
                        ROnExecuteProcessResponse.Output = _Cmd_Output;
                    }
                    if (ProcessOutputType == Enum_ProcessOutputType.File)
                    {
                        ROnExecuteProcessResponse.Output = System.IO.File.ReadAllText(OutputFile);
                    }
                }



                if (timer_for_hide_window != null)
                {
                    timer_for_hide_window.Stop();
                }
            }
            catch (Exception ex)
            {
                if (timer_for_hide_window != null)
                {
                    timer_for_hide_window.Stop();
                }

                ROnExecuteProcessResponse.Errors.AddErrorToErrorList(MethodBase.GetCurrentMethod().ToString(), ex.Message);
            }
            return(ROnExecuteProcessResponse);
        }
Exemplo n.º 5
0
        public void StartWatching()
        {
            while (keepRunning)
            {
                System.Threading.Thread.Sleep(1000);
                OnExecuteProcessResponse ExecuteResponse = _m_Process_Manager.OnExecuteProcess("netsh.exe", "wlan show interfaces", ProcessOutputType: _m_Child_Process.Enum_ProcessOutputType.Cmd, FullHide: false);
                string Output = ExecuteResponse.Output;
                //TODO Add to db
                if (!Output.Contains("There is no wireless interface on the system"))
                {
                    _m_WiFi_Watcher_Node mwwn = new _m_WiFi_Watcher_Node();
                    mwwn.date = DateTime.Now;
                    string[] lines = Output.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string line in lines)
                    {
                        string[] SplitedByColon = line.Split(new[] { " : " }, StringSplitOptions.RemoveEmptyEntries);
                        if (SplitedByColon.Length < 2)
                        {
                            continue;
                        }
                        string PropertyName = SplitedByColon[0].TrimStart().TrimEnd();
                        if (PropertyName != "")
                        {
                            string PropertyValue = SplitedByColon[1].TrimStart();
                            if (PropertyValue != "")
                            {
                                if (PropertyName == "Name")
                                {
                                    mwwn.Name = PropertyValue;
                                }
                                else if (PropertyName == "Description")
                                {
                                    mwwn.Description = PropertyValue;
                                }
                                else if (PropertyName == "GUID")
                                {
                                    mwwn.GUID = PropertyValue;
                                }
                                else if (PropertyName == "Physical address")
                                {
                                    mwwn.Physical_address = PropertyValue;
                                }
                                else if (PropertyName == "State")
                                {
                                    mwwn.State = PropertyValue;
                                }
                                else if (PropertyName == "SSID")
                                {
                                    mwwn.SSID = PropertyValue;
                                }
                                else if (PropertyName == "BSSID")
                                {
                                    mwwn.BSSID = PropertyValue;
                                }
                                else if (PropertyName == "Network type")
                                {
                                    mwwn.Network_type = PropertyValue;
                                }
                                else if (PropertyName == "Radio type")
                                {
                                    mwwn.Radio_type = PropertyValue;
                                }
                                else if (PropertyName == "Authentication")
                                {
                                    mwwn.Authentication = PropertyValue;
                                }
                                else if (PropertyName == "Cipher")
                                {
                                    mwwn.Cipher = PropertyValue;
                                }
                                else if (PropertyName == "Connection mode")
                                {
                                    mwwn.Connection_mode = PropertyValue;
                                }
                                else if (PropertyName == "Channel")
                                {
                                    mwwn.Channel = PropertyValue;
                                }
                                else if (PropertyName == "Receive rate (Mbps)")
                                {
                                    mwwn.Receive_rate = PropertyValue;
                                }
                                else if (PropertyName == "Transmit rate (Mbps)")
                                {
                                    mwwn.Transmit_rate = PropertyValue;
                                }
                                else if (PropertyName == "Signal")
                                {
                                    mwwn.Signal = PropertyValue;
                                }
                                else if (PropertyName == "Profile")
                                {
                                    mwwn.Profile = PropertyValue;
                                }
                                else if (PropertyName == "Hosted network status")
                                {
                                    mwwn.Hosted_network_status = PropertyValue;
                                }
                            }
                        }
                    }


                    if (!mwwDB.WifiIsRecordedOrStateChanged(mwwn.Physical_address, mwwn.State))//is new record
                    {
                        mwwDB.AddWifiToDB(mwwn);
                    }
                }
            }
        }