Exemplo n.º 1
0
        public static List <NetworkInteface> GetNetworkInterfaces()
        {
            var cards = GetNetworkCards();

            var interfaces = (Bash.Execute("ifconfig -a")).OutputList;

            return(ExtractNetworkInterfaces(cards, interfaces));
        }
        public static CommandResult CreateYaml(string networkInterfaceName, string ip, string mask, string gateway, string nameServersAddresses, string password, bool backup = true)
        {
            var content = GetYamlTemplate(networkInterfaceName, ip, mask, gateway, nameServersAddresses);

            var outputfile = YAML_FILE;

            var currentdir = Directory.GetCurrentDirectory();
            var tmpfile    = Path.Combine(currentdir, System.IO.Path.GetFileName(outputfile));

            File.WriteAllText(tmpfile, content);
            Bash.Execute($"chmod 640 {tmpfile}");

            if (backup && File.Exists(YAML_FILE))
            {
                var backupfilename = $"{YAML_FILE}-{DateTimeExtensions.NowToFilenameString()}.backup";
                Bash.Execute($"cp {YAML_FILE} {backupfilename}", password: password);
            }

            var result = Bash.Execute($"mv {tmpfile} {outputfile}", password: password);

            Bash.Execute($"chmod 640 {outputfile}");
            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// ls /sys/class/net -1"
        /// </summary>
        /// <returns></returns>
        ///
        public static List <string> GetNetworkCards()
        {
            var result = Bash.Execute("ls /sys/class/net -1");

            return(result.OutputList);
        }