开发者

get ip address of all connected pc in c# [duplicate]

开发者 https://www.devze.com 2023-02-18 07:10 出处:网络
This question already exists: Closed 11 years ago. Possible Duplicate: get ip address of all pc on my pc which is connected in lan in c#
This question already exists: Closed 11 years ago.

Possible Duplicate:

get ip address of all pc on my pc which is connected in lan in c#

This is my code.I give only ip address of my computer but i want to ip address of all computer which is connected in lan.also i give the troubleshoot error in this code. please give me the solution with changes of code.

static void Main(string[] args)
{
    System.Diagnostics.Process p = new System.Diagnostics.Process();
    p.StartInfo.FileName = "cmd ";
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.Arguments = "/C net view";
    p.StartInfo.RedirectStandardOutput = true;
    p.Start();
    String output = p.StandardOutput.ReadToEnd();
    char[] delimiters = new char[] { '\n' };
    String strHostName = string.Empty;

    string[] s = output.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
    IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
    IPAddress[] addr = ipEntry.AddressList;



    p.WaitForExit();
    int z = s.Length - 5;


    string[] str1 = new string[z];
    int i = 0;
    char[] saperator = { ' '};
    for (int j = 3; j < s.Length - 2; 开发者_运维知识库j++, i++)
    {

        str1[i] = (s[j].ToString()).Split(saperator)[0] ;
        Console.WriteLine("IP Address {0}: {1} ", i, addr[i].ToString());
    }
     //Console.WriteLine(output);

    Console.ReadLine();
}


Im not exactly a professional but i think what you need is called a port scanner, you can implement the very basic functionality of a port scanner into your app and read all the live ips in your network

one solution would be: http://www.geekpedia.com/tutorial142_Creating-a-Port-Scanner-with-Csharp.html

they even have code available for download on the site. haven't tried downloading it tough. :)

0

精彩评论

暂无评论...
验证码 换一张
取 消