Tag: ping

System.Net.NetworkInformation.Ping崩溃

所以,我有一个拥有600多台设备的网站。 我正在尝试使用标准的.NET ping类逐个ping它们。 由于某种原因,这个线程崩溃了 – 几天后它就停止响应了。 它只是在网络上ping设备。 我们正在使用Microsoft Windows Server 2008 R2。 .NET ping类有什么问题吗? 我似乎也遇到了内存泄漏,我猜测是由于ping。 我应该写一个win32 ping dll为我做这个工作还是我做错了.NET? private void PingDevice(out bool state, string IP) { PingReply pingReply; System.Net.NetworkInformation.Ping pingSender = null; state = false; try { pingSender = new System.Net.NetworkInformation.Ping(); pingReply = pingSender.Send(IP, 4000); state = (pingReply.Status == IPStatus.Success); // comms is on/off } […]

.NET Ping()给出错误的超时?

我有一个循环的脚本,每秒向主机发送一次ping。 其目的是测试我的家庭网络上的无线性能。 问题是,我似乎从我的脚本中获得超时,而任一客户端(pingER和pingEE)上的标准“ping -t”都没有这样的超时。 事实上,在最后30分钟内没有一次超时,而我的脚本每隔几分钟就收到超时回复。 我的基本脚本如下。 在所有情况下,当它确实发生时,我的回复是TimedOut,响应时间为0ms。 我的脚本是否导致错误超时? 谢谢。 编辑:更新代码以反映最新的更改,仍然具有相同的行为。 while (true) { System.Threading.Thread.Sleep(delay); var builder = new StringBuilder(); hosts.ForEach(h => { var buffer = new byte[32]; var reply = ping.Send(h, 4000, buffer, new PingOptions(600, true)); var error = reply.Status != IPStatus.Success || reply.RoundtripTime > maxRoundTrip; if (verbose || error) { builder.AppendFormat(“{0}: {1} ({2}ms)”, h, […]

使用WMI和C#检测机器是在线还是离线

我在使用Win2003服务器的LAN网络中使用vs2008,winxp。 我想在winxp中安装一个应用程序来检测win2003机器是在线还是离线,如果在启动它时是否脱机。 我有这个参考,任何更多的参考,代码示例和最佳实践? http://danielvl.blogspot.com/2004/06/how-to-ping-in-c-using.html http://snipplr.com/view/2157/ping-using-wmi-pingstatus/ The popular C# Ping Utitility http://www.visualbasicscript.com/Ping-WMI-amp-NonWMI-Versions-Functions-amp-Simple-Connectivity-Monitor-m42535.aspx

Ping.SendAsync()从0.0.0.0返回重播,如何获取ping地址?

我在C#中遇到Ping.SendAsync()函数的问题。 我ping一些ip地址,但有些错误。 我需要从列表中删除错误的地址。 但是如何,因为p_PingCompleted 事件args.replay.adress是0.0.0.0 ? 这是我的代码: System.Collections.Generic.List GameList = new System.Collections.Generic.List(); System.Timers.Timer timer = new System.Timers.Timer(5000); public StartServer() { this.tcpListener = new TcpListener(IPAddress.Any, 8888); this.listenThread = new Thread(new ThreadStart(ListenForClients)); this.listenThread.Start(); Console.WriteLine(“Master server running…”); timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); timer.Start(); } void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { Game[] games = GameList.ToArray(); foreach (Game curgame in games) […]

C#ping minecraft

所以发现这个小代码片段可以让你用PHP ping一个Minecraft服务器,但现在我想用C#做这个。 我尝试自己这样做,但由于某种原因它只是不起作用 UdpClient client = new UdpClient(); IPEndPoint ep; try { ep = new IPEndPoint(IPAddress.Parse(“-snip-“), -snip-); client.Connect(ep); } catch { Console.WriteLine(“Error”); Console.ReadLine(); return; } byte[] bytes = new byte[1]; bytes[0] = (byte)0xFE; client.Send(bytes, bytes.Length); IPEndPoint rep = new IPEndPoint(IPAddress.Any, 0); byte[] recv = client.Receive(ref rep); Console.WriteLine(ASCIIEncoding.ASCII.GetString(recv)); Console.ReadLine(); 服务器似乎完全忽略了数据包。 这是我找到的代码片段: $fp = fsockopen($host, $port, $errno, […]

从移动设备获取Lan中的所有IP主机

我希望在移动设备(C#.net紧凑框架)上获得包含网络中所有IP地址的列表。 我读了几篇像这样的文章。 问题是,在我的移动设备上我无法ping它们异步因为我只有opennetcf,它不支持它。 ping它同步需要太长时间。 你知道一个图书馆这样做或者你知道吗,我怎么能找到我网络中的所有主机,甚至可能没有ping(这很慢) 端口没关系,我只是想知道,使用了哪些IP … 谢谢你,卡尔

虽然存在依赖关系和使用,但找不到类型或命名空间名称“Ping”

我正在创建一个程序来ping网络中的计算机。 为此,我试图使用类ping,来自 namespace System.Net.NetworkInformation.Ping 我正在使用ASP.NET 5.0所以我hava project.json文件与我的dependecies { “version”: “1.0.0-*”, “dependencies”: { “NetworkSniffer”: “1.0.0-*”, “Microsoft.AspNet.Mvc”: “6.0.0.0-beta2” }, “commands”: { “run”: “run” }, “frameworks”: { “aspnet50”: { “dependencies”: { “System.Console”: “4.0.0-beta-22231”, “System.Net.NetworkInformation”: “4.0.10-beta-22231” } }, “aspnetcore50”: { “dependencies”: { “System.Console”: “4.0.0-beta-22231”, “System.Net.NetworkInformation”: “4.0.10-beta-22231” } } } } 一个简单版本的控制台代码仍然给出错误: using System.Net.NetworkInformation; namespace TestApp { public class Program […]

Windows窗体应用程序中的任务并行库代码冻结 – 作为Windows控制台应用程序正常工作

这个问题是我曾问过的上一个问题的后续问题: 如何使用C#并行执行多个“Ping” 我能够获得接受的答案(Windows控制台应用程序),但是当我尝试在Windows窗体应用程序中运行代码时,以下代码将冻结在包含Task.WaitAll(pingTasks.ToArray()) 。 这是我试图运行的代码: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Net.NetworkInformation; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { List addresses = new List(); for (Int32 i […]

如何在不使用ping的情况下检查Web服务是否已启动并运行?

如何检查Web服务中的方法是否正常工作? 我不能用ping。 我仍然想检查客户端从Web服务调用的任何方法。 我知道很难概括,但应该有一些方法。

如何同时异步进行多次ping操作?

我似乎无法理解如何构建对SendPingAsync的异步调用。 我想循环遍历一个IP地址列表,并在继续执行程序之前异步ping它们…现在需要一次一个地遍历所有这些地址。 我之前问了一个关于它的问题,我认为我能够找出异步,但显然我错了。 private void button1_Click(object sender, EventArgs e) { this.PingLoop(); MessageBox.Show(“hi”); //for testing } public async void PingLoop() { Task longRunningTask = PingAsync(); int result = await longRunningTask; MessageBox.Show(“async call is finished!”); //eventually want to loop here but for now just want to understand how this works } private async Task PingAsync() { Ping […]