Discovery of hosts connected to the LAN

In order to create lan messenger in C #, I need to discover host computers on the Internet, obviously using the same mailbox software. I tried to find a starting point to do this, but in vain. I need to know how to get started.

+3
source share
7 answers

In the past, I did this in two ways: connecting all clients to a predefined host (simple, but requiring some client configuration) and having a host (or client) to translate their existence through "translation", address (for example, 10.0.255.255) (hard, firewalls / NAT can make life painful; clients do not need to be configured).

But yes, if WCF implements the discovery protocol, go with it. If he does what you want, he is probably better than anything you (or most people, for that matter) could write.

+2
source

Can I use the Windows Connection Foundation? If so, you can use WCF to implement the WS-Discovery protocol. Here is a brief description .

+1
source

, , :

1) . , , .

2) : , . ( , WCF, ) .

UDP. , , , . , , , . , .

WCF , . .

+1

GetComputers(), LAN Messenger

using System.Diagnostics;

public static string[] GetComputers()
{
    //Process that retrieves the net view >> list of computers on the network
    Process proc = new Process();
    proc.StartInfo.FileName = "net.exe";
    proc.StartInfo.CreateNoWindow = true;
    proc.StartInfo.Arguments = "view";
    proc.StartInfo.RedirectStandardOutput = true;
    proc.StartInfo.UseShellExecute = false;
    proc.Start();

    //Reads the output of the net view.
    StreamReader sr = new StreamReader(proc.StandardOutput.BaseStream);
    string line = "";

    List<string> names = new List<string>();
    while ((line = sr.ReadLine()) != null)
    {
        if (line.StartsWith(@"\\"))
            names.Add(line.Substring(2).Split(' ')[0].TrimEnd());
    }

    sr.Close();
    proc.WaitForExit();

    //Array that contains computer names
    string[] computerNames = new string[names.Capacity];
    int i = 1;

    //Adds computers names to the list view
    foreach (string name in names)
    {
        computerNames[i] = name;
        i++;
    }

    return computerNames;
}
+1

, , - , - , IP.

, , UDP, IP. "" IP- ( - ). , IP-. IP- "" - .

, , (, + (10) ).

, . , , ips .

0

, ping ip . - . , , - - .

- , " !" .

0

Source: https://habr.com/ru/post/1705163/


All Articles