c# - 检测计算机上是否启用了链接层拓扑

标签 c# networking

我们的支持团队已诊断出计算机配置的某些特定区域可能会导致我们基于网络的数据库应用程序运行缓慢。我的任务是创建一个工具来测试可能的减速问题。我在检测是否在 Windows 中为其事件网络适配器启用了链接层拓扑时遇到问题。我有一种方法可以找到事件的(最常用的)网络适配器。

是否有检测链接层拓扑的方法以及如何测试它?

最佳答案

不是纯 .Net 解决方案,但似乎有效。函数接受本地连接的名称和协议(protocol)名称。我有一个指向具有许多不同协议(protocol)驱动程序名称的站点的链接,但代码中包含了您想要的名称。

这使用 nvspbind.exe,您可以从 http://archive.msdn.microsoft.com/nvspbind 获得它.

代码

class Program
{
    static void Main(string[] args)
    {
        //check Link-Layer Topology Discover Mapper I/O Driver
        bool result1 = IsProtocalEnabled("Local Area Connection", "ms_lltdio");
        //check Link-Layer Topology Discovery Responder
        bool result2 = IsProtocalEnabled("Local Area Connection", "ms_rspndr");
    }

    private static bool IsProtocalEnabled(string adapter, string protocol)
    {
        var p = new System.Diagnostics.Process();
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.FileName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "nvspbind.exe");
        p.StartInfo.Arguments = string.Format("/o \"{0}\" {1}", adapter, protocol);

        p.Start();

        string output = p.StandardOutput.ReadToEnd();

        p.WaitForExit();

        return output.Contains("enabled");
    }
}

我从这里得到了协议(protocol)驱动程序名称:http://djseppie.wordpress.com/category/windows/scripting/

关于c# - 检测计算机上是否启用了链接层拓扑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10691874/

相关文章:

c# - Resharper 提议从 WPF 中的 Window 类中删除冗余继承

iphone - 使用非默认 DNS 服务器的 DNS TXT 记录查询

c# - Xna (C#) 和 C++ 的网络?

linux - 为导出设备 linux 内核构建一个 sk_buff

java - 在 Android 设备上查找 netMask

c# - 如何使用蛋糕仅更新 assemblyinfo.cs 中的版本信息?

c# - 返回泛型类型的函数,其值仅在运行时已知

c# - 如何统一使用 JsonUtility 获取子数组

c# - 优化 LINQ-to-SQL 查询

networking - 为什么会有这么多环回地址?