(windows app C#) need help scanning local network devices on windows 10

Deadlock 21 Reputation points
2021-08-19T23:40:25.453+00:00

So when you type "arp - a" into a command prompt it gives a list of local devices and MAC address connected to my internet. I want to know how to turn That into a windows app form in C#

If anyone can help that would be nice

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,404 questions
Windows 10 Network
Windows 10 Network
Windows 10: A Microsoft operating system that runs on personal computers and tablets.Network: A group of devices that communicate either wirelessly or via a physical connection.
2,402 questions
{count} votes

Accepted answer
  1. Timon Yang-MSFT 9,606 Reputation points
    2021-08-20T06:09:31.437+00:00

    We can use Process to call cmd to execute this command, and then convert the result into an object in c#.

        class Program  
        {  
            static void Main(string[] args)   
            {  
                ArpUtil arpHelper = new ArpUtil();  
                List<ArpItem> arpEntities = arpHelper.GetArpResult();  
                foreach (var item in arpEntities)  
                {  
                    Console.WriteLine(item.Ip+"\t"+item.MacAddress+"\t"+item.Type);  
                }  
                Console.ReadLine();  
            }  
        }  
        public class ArpItem  
        {  
            public string Ip { get; set; }  
      
            public string MacAddress { get; set; }  
      
            public string Type { get; set; }  
        }  
        public class ArpUtil  
        {  
            public List<ArpItem> GetArpResult()  
            {  
                using (Process process = Process.Start(new ProcessStartInfo("arp", "-a")  
                {  
                    CreateNoWindow = true,  
                    UseShellExecute = false,  
                    RedirectStandardOutput = true  
                }))   
                {  
                    var output = process.StandardOutput.ReadToEnd();  
                    return ParseArpResult(output);  
                }  
            }  
      
            private List<ArpItem> ParseArpResult(string output)  
            {  
                var lines = output.Split('\n');  
      
                var result = from line in lines  
                             let item = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)  
                             where item.Count() == 4  
                             select new ArpItem()  
                             {  
                                 Ip = item[0],  
                                 MacAddress = item[1],  
                                 Type = item[2]  
                             };  
      
                return result.ToList();  
            }  
        }  
    

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.