C# 获取没有 DNS 的网络上所有计算机的列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/105676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 14:12:15  来源:igfitidea点击:

Get a list of all computers on a network w/o DNS

提问by AlexeyMK

Greetings,

你好,

I need a way (either via C# or in a .bat file) to get a list of all the computers on a given network. Normally, I use "net view", but this tends to work (from my understanding) only within your domain. I need the names (or at least the IP Addresses) of all computers available on my network.

我需要一种方法(通过 C# 或 .bat 文件)来获取给定网络上所有计算机的列表。通常,我使用“网络视图”,但这往往(根据我的理解)仅在您的域内起作用。我需要网络上所有可用计算机的名称(或至少是 IP 地址)。

Being able to get all computers on a domain that isn't mine (in which case I'd use WORKGROUP, or whatever the default is) would also work.

能够在不属于我的域中获取所有计算机(在这种情况下,我将使用 WORKGROUP 或任何默认设置)也可以。

采纳答案by Whisk

Nmapis good for this - use the -O option for OS fingerprinting and -oX "filename.xml" for outputas xml that you can then parse from c#.

Nmap对此很有用 - 使用 -O 选项进行操作系统指纹识别,使用 -oX "filename.xml"作为 xml输出,然后您可以从 c# 解析。

A suitable commandline would be (where 192.168.0.0/24 is the subnet to scan):

合适的命令行是(其中 192.168.0.0/24 是要扫描的子网):

nmap -O -oX "filename.xml" 192.168.0.0/24

leave out the -O if you aren't interested in guessing the OS - if you just want a ping sweep use -sP, or read the docs for the myriad other options.

如果您对猜测操作系统不感兴趣,请省略 -O - 如果您只想进行 ping 扫描,请使用 -sP,或者阅读文档以了解无数其他选项。

回答by UnkwnTech

Ping everything in the rage, then you can get netbios info from the systems that respond to identify it's name.

Ping 愤怒的所有内容,然后您可以从响应识别其名称的系统中获取 netbios 信息。

回答by EricSch

In one of my web app I used the NetApi32 function for network browsing.

在我的一个网络应用程序中,我使用 NetApi32 函数进行网络浏览。

Code: http://gist.github.com/11668

代码:http: //gist.github.com/11668

回答by Alnitak

To expand on what Unkwntech has said -

扩展Unkwntech所说的内容-

You can also do a "broadcast" ping to avoid having to ping each IP address individually.

您还可以执行“广播”ping 以避免必须单独 ping 每个 IP 地址。

Immediately after than you can use "arp" to examine the ARP cache and get a list of which IP addresses are on which MAC address.

紧接着您可以使用“arp”来检查 ARP 缓存并获取哪些 IP 地址位于哪些 MAC 地址的列表。