同时Ping许多设备 [英] Ping many devices simultaneously

查看:103
本文介绍了同时Ping许多设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有一个关于Ping许多设备并在网络表单上显示其状态的问题.

我正在动态创建一个表.将为数据库中的每台计算机创建一行,其中一个单元是设备的IP地址.

该表的最后一个单元格显示设备是联机还是脱机.这是通过ping方法确定的.由于数据库有100多个设备,因此一次ping一个设备的效率不是很高.

我正在寻找关于同时对多个设备执行ping操作的建议.我知道System.Net.Ping具有SendAsync方法,但是,我不确定这是否是解决方案.有人可以告诉我吗?

谢谢.

Hello,

I have a question about Pinging many devices and displaying their status on a webform.

I am dynamically creating a table. A row is created for every computer in a database, and one of the cells is the IP address of the device.

The last cell of the table shows whether the device is online or offline. This is determined by the ping method. Because the database has over 100 devices, pinging one at a time is not very efficient.

I am looking for suggestions to perform pings for multiple devices at the same time. I know that System.Net.Ping has the SendAsync method, however, I am not sure if this is the solution. Can someone who has done this let me know?

Thank you.

推荐答案

我不明白为什么不这样做.如果要同时ping多个IP,则System.Net.NetworkInformation.SendAsync方法之一将真正使您节省时间.我看到的唯一选择是创建相同数量的线程(最好使用线程池或BackgroundWorker),并在每个单独的线程中同步ping每个单独的IP.



让我们回到SendAsync.如何等待所有ping请求?看这个例子:
http://msdn.microsoft.com/en-us/library/ms144961.aspx [ ^ ].

它显示了如何等待AutoResetEvent(只是一个),这是从System.Threading.WaitHandle派生的类.如何等待他们全部?对所有ping使用AutoResetEvent的相同实例,对等待使用System.Threading.WaitHandle.WaitAll.试试吧.

—SA
I cannot see why not. One of the System.Net.NetworkInformation.SendAsync methods will really allow you to save time if you want to ping several IPs at the same time. The only alternative I see would be creating the same number of threads (preferably using the thread pool or BackgroundWorker) and pinging synchronously each separate IP in each separate thread.



Let''s get back to SendAsync. How to wait for all of the ping requests? Look at this example:
http://msdn.microsoft.com/en-us/library/ms144961.aspx[^].

It shows how to wait for AutoResetEvent (just one), which is a class derived from System.Threading.WaitHandle. How to wait for them all? Use the same instance of AutoResetEvent for all pings and use System.Threading.WaitHandle.WaitAll for wait. Try it.

—SA


如果所有设备都在同一子网中,则可以执行以下操作:
1.删​​除arp缓存. (在命令行上为"arp -d".)

2.用几次ping(〜10)ping子网的广播地址.确保使用实际的广播地址,即192.168.0.255而不是255.255.255.255.

3.通过在命令行上使用"arp -a"或使用p/Invoke GetIpNetTable在计算机的ARP表中查找IP地址.如果地址在arp表中,则计算机响应了您的ping.

该链接给出了在C#中使用GetIpNetTable的示例:
http://stackoverflow.com/questions/1148778/how- do-i-access-arp-protocol-information-through-net [
If all the devices are on the same subnet, you can do as follows:
1. Delete the arp cache. ("arp -d" on the command line.)

2. Ping the broadcast address for the subnet with several pings (~10). Make sure to use the actual broadcast address, i.e. 192.168.0.255 not 255.255.255.255.

3. Look up the IP addresses in the ARP table for your computer, either by using "arp -a" on the command line or GetIpNetTable using p/Invoke. If the address is in the arp table, the computer responded to your ping.

This link gives and example using GetIpNetTable in C#:
http://stackoverflow.com/questions/1148778/how-do-i-access-arp-protocol-information-through-net[^]


这篇关于同时Ping许多设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆