Beispiel #1
0
        //typeperf "\Processor(_Total)\% Processor Time"
        public string Get(SystemUpTimeData request)
        {
            var      info = string.Empty;
            TimeSpan upTime;

            switch (IsUnix())
            {
            case true:
                info   = LinuxBash.GetCommandOutput("uptime -s");
                upTime = (DateTime.Now - DateTime.Parse(info));
                return(JsonSerializer.SerializeToString(new SystemUpTimeData()
                {
                    UpTimeDays = upTime.Days.ToString(),
                    UpTimeHours = upTime.Hours.ToString()
                }));

            case false:
                info = WindowsCmd.GetCommandOutput("net statistics server");
                var info1 = info.Split(new[] { "Statistics since" }, StringSplitOptions.RemoveEmptyEntries)[1];
                var info2 = info1.Split(new[] { "Sessions accepted" }, StringSplitOptions.RemoveEmptyEntries)[0];
                upTime = (DateTime.Now.Subtract(DateTime.Parse(info2)));

                return(JsonSerializer.SerializeToString(new SystemUpTimeData()
                {
                    UpTimeDays = upTime.Days.ToString(),
                    UpTimeHours = upTime.Hours.ToString()
                }));

            default:
                return(string.Empty);
            }
        }
        public static string BlockIpConnection(Connection connection)
        {
            var netshArgs =
                $"advfirewall firewall add rule name=\"{connection.RuleName}\" dir=in interface=any action=block enable=yes profile=Any remoteip=\"{connection.Ip}\"";
            var result = WindowsCmd.GetCommandOutput("netsh.exe", netshArgs);

            return(result); //OK
        }
        public static string AllowIpConnection(Connection connection)
        {
            var netshArgs =
                $"advfirewall firewall delete rule name=\"{connection.RuleName}\" remoteip=\"{connection.Ip}\"";
            var result = WindowsCmd.GetCommandOutput("netsh.exe", netshArgs);

            return(result); //OK
        }
Beispiel #4
0
        private GraphicsProcessor GetGraphicsProcessorData()
        {
            //Nvidea GPU Info
            var gpuCommandArgsTemp    = @"--query-gpu=temperature.gpu --format=csv,noheader";
            var gpuCommandArgsPercent = @"--query-gpu=utilization.gpu --format=csv,noheader";

            return(new GraphicsProcessor()
            {
                Percentage = WindowsCmd.GetCommandOutput(@"C:\Program Files\NVIDIA Corporation\NVSMI\nvidia-smi.exe", gpuCommandArgsPercent).Trim(),
                Temp = WindowsCmd.GetCommandOutput(@"C:\Program Files\NVIDIA Corporation\NVSMI\nvidia-smi.exe", gpuCommandArgsTemp).Trim()
            });
        }
Beispiel #5
0
        public static bool FirewallConnectionRuleExists(Connection connection)
        {
            var result = string.Empty;

            switch (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
            case true:
                result = WindowsCmd.GetCommandOutput("netsh.exe",
                                                     $" advfirewall firewall show rule name=\"{connection.RuleName}\"");
                return(result != "No rules match the specified criteria");

            case false:
                result = LinuxBash.GetCommandOutput($"iptables -L INPUT -v -n | grep \"{connection.Ip}\"");
                //We need a result example to condition this:
                //if result is ?? then move on, else add the ip
                break;
            }

            return(false);
        }
        //typeperf "\Processor(_Total)\% Processor Time"
        public string Get(SystemUpTimeData request)
        {
            var      config = Plugin.Instance.Configuration;
            var      info   = string.Empty;
            TimeSpan upTime;

            switch (IsUnix())
            {
            case true:
                info   = LinuxBash.GetCommandOutput("uptime -s");
                upTime = (DateTime.Now - DateTime.Parse(info));
                return(JsonSerializer.SerializeToString(new SystemUpTimeData()
                {
                    UpTimeDays = upTime.Days.ToString(),
                    UpTimeHours = upTime.Hours.ToString(),
                    UpTimeMinutes = upTime.Minutes.ToString(),
                    UpTimeSeconds = upTime.Seconds.ToString()
                }));

            case false:

                info = WindowsCmd.GetCommandOutput("cmd", " /c wmic path Win32_OperatingSystem get LastBootUpTime");
                var info1 = info.Split(new[] { "LastBootUpTime" }, StringSplitOptions.RemoveEmptyEntries)[0].Trim();
                var info2 = info1.Split('-')[0].Split('.')[0];
                var info3 = info2.Insert(4, "/").Insert(7, "/").Insert(10, " ").Insert(13, ":").Insert(16, ":");
                upTime = (DateTime.Now.Subtract(DateTime.Parse(info3)));

                return(JsonSerializer.SerializeToString(new SystemUpTimeData()
                {
                    UpTimeDays = upTime.Days.ToString(),
                    UpTimeHours = upTime.Hours.ToString(),
                    UpTimeMinutes = upTime.Minutes.ToString(),
                    UpTimeSeconds = upTime.Seconds.ToString()
                }));

            default:
                return(string.Empty);
            }
        }