Beispiel #1
0
        public static List <(string IpAddress, string Mac)> GetIpAddresses()
        {
            List <(string IpAddress, string Mac)> ipList = null;

            try
            {
                ipList = ArpTable.GetArpTable();
            }
            catch (Exception)
            {
                return(null);
            }
            return(ipList);
        }
Beispiel #2
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;
        }