List the IP Address of all computers connected to a single LAN(列出连接到单个 LAN 的所有计算机的 IP 地址)
问题描述
我正在编写一个程序,您可以在其中出于各种原因连接到 LAN 中的其他计算机.但是,与其输入多台计算机的 IP 地址(很麻烦),我想知道是否有办法列出局域网中所有计算机的 IP 地址.我研究了一整天,还没有找到合适的.这是因为没有这种东西存在吗?提前谢谢你.
I am writing a program where you connect, for various reasons, to other computers in a LAN. However, rather than having to input the IP address for multiple computers (a pain in the butt), I was wondering if there is a way to list the IP addresses of all the computers in a LAN. I have researched all day, and as of yet have found nothing suitable. Is this because nothing of this sort exists? Thank you in advance.
看起来这篇文章获得了很多观点,我应该发布我的实际解决方案.通常,局域网中计算机 IP 地址的命名约定是相同的.例如 192.168.2.*,* 被替换为任何有效数字.我的程序检测到 IP 地址,将其显示给用户,然后询问前 3 个 IP 块.然后,它通过 ping 并等待响应按给定的 IP 命名约定顺序扫描多达 200 个.没有反应,没有电脑.一旦它知道它背后有一台计算机,它就可以做你可以用 IP 做的所有事情.
It would seem that with the many views this post is getting, I should post my actual solution. In general, the naming conventions for computers IP addresses on a LAN are the same. example being 192.168.2.*, * being replaced with any valid number. My program detects the IP address, displays it to the user, then asks for the first 3 blocks of IP. It then sequentially scans up to 200 in the given IP naming convention by pinging and waiting for a response. No response, no computer. It can do everything you can do with an IP once it knows it has a computer behind it.
推荐答案
你真的找不到比 ping
ing 或 arping
ing 地址更可靠的方法了同一个子集.在我第一次实习的那天,我为某个软件实现了这个,最后一次我检查(公平地说是几年前),这就是他们仍在使用这个功能的东西.我认为这意味着他们没有找到更好的东西.
You're not really going to find anything more reliable than ping
ing or arping
ing addresses on the same subset. I implemented this for a certain piece of software back in the day on my first internship and, last time I checked (to be fair it was several years ago), that is what they were still using for this functionality. I take that to mean that they haven't found anything better.
找到这些的源代码并将它们翻译成 C# 并不难.ping
, arping
.或者,您只需打开命令提示符并执行 ping
然后解析结果.
It is not hard to find the source code for these and translate them to C#. ping
, arping
. Alternatively, you just shell out to a command prompt and execute ping
and then parse the results.
这篇关于列出连接到单个 LAN 的所有计算机的 IP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!