Пример #1
0
        public override void OnReport(Report report)
        {
            base.OnReport(report);

            report.Add("ip addr show", (LocateExecutable("ip") != "") ? SystemShell.Shell2(LocateExecutable("ip"), "addr", "show") : "'ip' " + LanguageManager.GetText("NotFound"));
            report.Add("ip link show", (LocateExecutable("ip") != "") ? SystemShell.Shell2(LocateExecutable("ip"), "link", "show") : "'ip' " + LanguageManager.GetText("NotFound"));
            report.Add("ip -4 route show", (LocateExecutable("ip") != "") ? SystemShell.Shell3(LocateExecutable("ip"), "-4", "route", "show") : "'ip' " + LanguageManager.GetText("NotFound"));
            report.Add("ip -6 route show", (LocateExecutable("ip") != "") ? SystemShell.Shell3(LocateExecutable("ip"), "-6", "route", "show") : "'ip' " + LanguageManager.GetText("NotFound"));
        }
Пример #2
0
        public override void OnJsonRouteList(Json jRoutesList)
        {
            base.OnJsonRouteList(jRoutesList);

            string o = "";

            o += SystemShell.Shell3(LocateExecutable("ip"), "-4", "route", "show");
            o += SystemShell.Shell3(LocateExecutable("ip"), "-6", "route", "show");

            foreach (string line in o.Trim().Split('\n'))
            {
                string   address = "";
                string   gateway = "";
                string   iface   = "";
                string   metric  = "";
                string[] fields  = line.Trim().CleanSpace().Split(' ');
                for (int i = 0; i < fields.Length; i++)
                {
                    if (i == 0)
                    {
                        address = fields[0];
                    }
                    else if ((fields[i] == "via") && (fields.Length > i))
                    {
                        gateway = fields[i + 1];
                    }
                    else if ((fields[i] == "dev") && (fields.Length > i))
                    {
                        iface = fields[i + 1];
                    }
                    else if ((fields[i] == "metric") && (fields.Length > i))
                    {
                        metric = fields[i + 1];
                    }
                }
                IpAddress ipGateway = new IpAddress(gateway);
                if (ipGateway.Valid == false)
                {
                    continue;
                }
                IpAddress ipAddress = IpAddress.DefaultIPv4;
                if (address == "default")
                {
                    if (ipGateway.IsV4)
                    {
                        ipAddress = IpAddress.DefaultIPv4;
                    }
                    else if (ipGateway.IsV6)
                    {
                        ipAddress = IpAddress.DefaultIPv6;
                    }
                }
                else
                {
                    ipAddress = new IpAddress(address);
                }
                if (ipAddress.Valid == false)
                {
                    continue;
                }

                Json jRoute = new Json();
                jRoute["address"].Value = ipAddress.ToCIDR();
                jRoute["gateway"].Value = ipGateway.ToCIDR();
                if (iface != "")
                {
                    jRoute["interface"].Value = iface;
                }
                if (metric != "")
                {
                    jRoute["metric"].Value = metric;
                }
                jRoutesList.Append(jRoute);
            }
        }