识别对C#中IP地址的ping请求? [英] Identify a ping request to an IP address in C#?

查看:95
本文介绍了识别对C#中IP地址的ping请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何找出系统是否已关闭或不使用其IP地址(考虑到我已获得IP地址列表)。

I want to know how to find out if a system is shutdown or not using its IP address (consider i have been provided list of IP addresses).

当前我有一个控制台应用程序,它将命令作为输入并在命令提示符下执行它,并在控制台上显示输出。

Currently i have a console application that is taking a command as an input and executing it on command prompt and showing me the output on the console.

class Program
{
    static void Main(string[] args)
    {
        Process cmdProcess = new Process();
        cmdProcess.StartInfo.FileName = "cmd.exe";
        cmdProcess.StartInfo.RedirectStandardInput = true;
        cmdProcess.StartInfo.RedirectStandardOutput = true;
        cmdProcess.StartInfo.CreateNoWindow = true;
        cmdProcess.StartInfo.UseShellExecute = false;
        cmdProcess.Start();      
    }
}


推荐答案

如果机器正在回复ping,按照@Paxz的建议,您可以执行以下操作:

If the machine is replying to pings, as per @Paxz 's suggestion, you can do this :

var ping = new Ping();
var pingReply = ping.Send("123.123.123.123");

if (pingReply.Status == IPStatus.Success)
{
}

这篇关于识别对C#中IP地址的ping请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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