用cmd或C#列出网络上的所有计算机

问题描述 投票:3回答:5

我需要获取网络上所有计算机的列表

该网络分为两个本地网络。一个管理网络和一个教育网络,然后在每个管理和教育网络下都有每个校园的子网。因此,每个校园都有一个Admin和一个Education Domain控制器。

我可以在每个子网的命令提示符下运行“网络视图”,以获取所有计算机的列表,但是我希望能够仅在一台服务器上运行,或者如果需要两台服务器(对于一台服务器,管理员网络和一个教育网络)

我知道有像nmap这样的应用程序可以做到这一点,但是我希望能够使用内置的Windows功能(例如“ net view”或自己写一些东西)。

其他详细信息:我有一个程序(由以前的开发人员编写),该程序作为后台服务运行,并且在每台计算机上都会启动一个弹出窗口,并在触发火警时播放.mp3文件。我想使用该程序并使用PsExec启动弹出窗口并播放消息,而不是在每台计算机上都安装该服务。我有PsExec工作,但需要获取所有计算机的列表。

c# networking ip psexec subnet
5个回答
10
投票

查找网络上所有活动/已使用的IP地址有一种非常巧妙的方法,您可以轻松地在网络上查找所有活动/已使用的IP地址,而无需任何第三方应用程序或更糟的情况,手动ping每个IP地址。

打开命令提示符并输入以下内容:

FOR / L%i IN(1,1,254)DO ping -n 1 192.168.10。%i |查找/ i“答复” >> c:\ ipaddresses.txt

更改192.168.10以匹配您自己的网络。


0
投票

您可能有一个运行Net View的批处理文件并将其转储到文本文件。由此,您可以对数据进行任何操作。这可以作为计划任务每​​天运行,或者在添加新计算机时手动运行。


0
投票

我不知道您使用的网络有多大,但是您可以尝试查询Active Directory。请在下面查看此链接以获取更多想法。

List of computers in Active Directory that are online


0
投票

您可以尝试这个吗?

代码C#:

// Get host name from current network
String strHostName = Dns.GetHostName();
List<string> machinesName = new List<string>();    

// Find host by name
IPHostEntry iphostentry = Dns.GetHostByName(strHostName);

// Enumerate IP addresses from current network
int nIP = 0;
foreach(IPAddress ipaddress in iphostentry.AddressList)
{
    host = Dns.GetHostByAddress(ipaddress);//ip Address is to be specified machineName
    //Add machine name into the list        
    machinesName.Add(host.HostName);
}

0
投票

您可以尝试:-使用C#代码:-/ *必须包含这些库* /

using System.Net;
using System.Net.Sockets; 

 private void GetIP()
    {
        Process netUtility = new Process();

        netUtility.StartInfo.FileName = "net.exe";

        netUtility.StartInfo.CreateNoWindow = true;

        netUtility.StartInfo.Arguments = "view";

        netUtility.StartInfo.RedirectStandardOutput = true;

        netUtility.StartInfo.UseShellExecute = false;

        netUtility.StartInfo.RedirectStandardError = true;

        netUtility.Start();



        StreamReader streamReader = new StreamReader(netUtility.StandardOutput.BaseStream, netUtility.StandardOutput.CurrentEncoding);



        string line = "";

        while ((line = streamReader.ReadLine()) != null)
        {

            if (line.StartsWith("\\"))
            {

                listBox1.Items.Add(line.Substring(2).Substring(0, line.Substring(2).IndexOf(" ")).ToUpper());

            }

        }

        streamReader.Close();
        netUtility.WaitForExit(1000);

    }

有关详细信息,我制作了一个Windows聊天应用程序,在其中我使用此代码来获取网络中系统名称的列表。您可以在那里查看其工作方式。链接为https://github.com/akki9c/wifi-chating/blob/master/chatSample/chatSample/Form1.cs

© www.soinside.com 2019 - 2024. All rights reserved.