c# - 如何检查特定IP地址是否连接到网络

标签 c# .net network-programming wifi

<分区>

我想创建一个应用程序来查找网络上的特定 IP 地址是否在线。我早就知道IP了。我是 C# 的新手,但想知道是否有人可以给我一个简单的解决方案。谢谢。

最佳答案

Ping ping = new Ping ();
IPAddress address = IPAddress.Parse("000.000.000.000");
PingReply pong = pingSender.Send(address);

pong 对象包含是否成功的信息。

if (pong.Status == IPStatus.Success)
{
  // your machine at address is up and responding
}

将使用这个的完整程序

using System;
using System.Net;
using System.Net.NetworkInformation;

public class Program
{
    public static void Main()
    {
        Ping ping = new Ping();
        //change the following ip variable into the ip adress you are looking for
        string ip = " ";
        IPAddress address = IPAddress.Parse(ip);
        PingReply pong = ping.Send(address);
        if (pong.Status == IPStatus.Success)
        {
            Console.WriteLine(ip + " is up and running.");
        }
    }
}

关于c# - 如何检查特定IP地址是否连接到网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38031446/

相关文章:

C# 如何从基类中的派生类获取特定类型的所有字段?

python - 扭曲不检测客户端断开连接

sockets - HTTP/1.1如何解决TCP重置问题?

c# - 使用 C# 通过 Skype 调用

c# - 如何检测应用程序是否受内存限制?

c# - 我应该使用什么数据类型来存储文本数据?

c# - 从另一个项目/dll 引用的 Asp.NET 用户控件具有 NULL 属性

c# - 在列表中查找具有最低属性值的项目

c# - 在 asp.net mvc 应用程序中从 Javascript 访问 C# 变量

c++ - 客户端关闭后 accept() 不阻塞(使用 Ctrl+C)错误 10093