Exemple #1
0
        private async void SetActiveDirectoryObjectComputers(bool IsCheck)
        {
            Debug.WriteLine("Start SetActiveDirectoryObjectComputers");
            //Debug.WriteLine(Environment.StackTrace);
            ComputerCircularProgressBar = IsCheck;
            Computers.Clear();
            Debug.WriteLine("Computers.Clear()");

            if (IsCheck)
            {
                TxtComputerCount = null;
                AllComputers     = await _ComputerCommandsviewModel.GetAllComputers();

                Debug.WriteLine(AllComputers.Count);
                AllComputers = AllComputers.OrderBy(a => a.SamAccountName).ToList();

                foreach (Principal item in AllComputers)
                {
                    computers.Add(item.Name);
                }
            }
            else
            {
                TxtComputerCount = null;
                Computers.Clear();
            }

            TxtComputerCount = Computers.Count.ToString();
            Debug.WriteLine("End SetActiveDirectoryObjectComputers");
        }
Exemple #2
0
        public void LoadFile(string path)
        {
            if (File.Exists(path))
            {
                using (StreamReader sr = new StreamReader(path, Encoding.Default))
                {
                    Computers.Clear();
                    Computer myComputer = new Computer();

                    string line = "";

                    while ((line = sr.ReadLine()) != null)
                    {
                        if (!line.StartsWith("#"))
                        {
                            if (line.IndexOf(";") >= 0)
                            {
                                string[] fields = line.Split(';');
                                myComputer = new Computer();
                                myComputer.ComputerName = fields[0];
                                myComputer.IPAddress    = fields[1];
                                myComputer.MACAddress   = fields[2];
                                myComputer.SubPool      = Convert.ToInt32(fields[3]);
                                myComputer.PreSelected  = false;
                                if (fields.Length == 5)
                                {
                                    if (fields[4].IndexOf("1") >= 0)
                                    {
                                        myComputer.PreSelected = true;
                                    }
                                }
                                Computers.Add(myComputer);
                            }
                        }
                    }
                }
                SetPreselected();
            }
        }
Exemple #3
0
        private async Task ScanLan_AsyncBody()
        {
            Status = AddComputersVM.Statuses.IsSearching;
            List <string> list = null;
            string        networkScanMethod = ViewModel.Instance.Workers.NetworkScanMethod;

            CancelSource = new CancellationTokenSource();
            var token = CancelSource.Token;

            switch (networkScanMethod)
            {
            case "NetApi32":
                list = await Task.Run(() =>
                                      (new NetworkBrowser()).GetNetworkComputers()
                                      ).WithCancellation(token);

                break;

            case "ArpTable":
                list = await Task.Run(async() => {
                    var ipList = ArpTable.GetIpAddresses();
                    if (ipList == null)
                    {
                        return(null);
                    }
                    var hostNames = await ArpTable.GetHostNames(ipList).WithCancellation(token);
                    return(hostNames);
                });

                break;
            }
            if (list == null || list.Count == 0)
            {
                Status = AddComputersVM.Statuses.NothingFound;

                string message     = "No LAN computer was detected.";
                string alternative = " Or you may select an alternative network scan method, this will re-initiate the search.";
                switch (networkScanMethod)
                {
                case "NetApi32":
                    message += " Check your cable and network settings and run \"net view\" CMD command to see if Windows actually sees anything on the network."
                               + alternative;
                    break;

                case "ArpTable":
                    message += " Check your cable and network settings and run \"arp -a\" CMD command to see if Windows actually detects any LAN IP."
                               + alternative;
                    break;

                default:
                    message = "Incorrect setting detected. Workers.cfg must contain either \"GetComputerNamesMethod\":\"NetApi32\" or \"GetComputerNamesMethod\":\"ArpTable\".";
                    break;
                }

                await Task.Delay(100);

                MessageBox.Show(message, "Nothing found", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }
            Computers.Clear();
            foreach (var entry in list)
            {
                dynamic pc = new ExpandoObject();
                pc.Name       = entry as string;
                pc.IsSelected = false;
                Computers.Add(pc);
            }
            Status = Statuses.Ready;
        }
        static void Main(string[] args)
        {
            try
            {
                if (stringDomainName != null)
                {
                    string[] info = TextProcessing.login();
                    while (true)
                    {
                        if (validateUser(info[0], info[1]))
                        {
                            goto PROCESS;
                        }
                        else
                        {
                            Console.Clear();
                            Console.Write("Invalid username or password. Try Again. (y/n): ");
                            string key = Console.ReadLine().ToUpper();
                            if (key.Equals("Y") || key.Equals("YES"))
                            {
                                info = TextProcessing.login();
                            }
                            else if (key.Equals("N") || key.Equals("NO"))
                            {
                                goto END;
                            }
                        }
                    }
PROCESS:
                    Console.Clear();
                    Console.WriteLine("Welcome!");
                    while (true)
                    {
                        Console.Write("Please select feature:\n[1]Show OU\n[2]Show User\n[3]Show Computer\n[4]Show Groups\n[5]Exit\n:");
                        string choose = Console.ReadLine();
                        switch (choose)
                        {
                        case "1":
                            OU.Clear();
                            OU = getOU();
                            foreach (string nameOU in OU)
                            {
                                Console.WriteLine(nameOU);
                            }
                            break;

                        case "2":
                            Users.Clear();
                            Users = getUsers();
                            foreach (User user in Users)
                            {
                                Console.WriteLine(user.SAMAccountName + " - " + user.commonName + " - " + user.ou);
                            }
                            break;

                        case "3":
                            Computers.Clear();
                            Computers = getComputer();
                            foreach (string computer in Computers)
                            {
                                Console.WriteLine(computer);
                            }
                            break;

                        case "4":
                            Groups.Clear();
                            Groups = getGroup();
                            foreach (string group in Groups)
                            {
                                Console.WriteLine(group);
                            }
                            break;

                        case "5":
                            Console.WriteLine("====================");
                            goto END;

                        default:
                            break;
                        }
                        Console.WriteLine("====================");
                    }
END:
                    Console.WriteLine("Goodbye!");
                }
                else
                {
                    Console.WriteLine("Your computer is not a member of domain");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }