如何查找给定IP地址的所有网络接口

时间:2014-07-02 07:24:10

标签: c# .net

如何查找给定IP地址的所有网络接口。

现在,我正在使用下面的代码来确定它,但它总是为本地计算机提供它,我想为给定的IP地址实现它。

NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in adapters)
{

    IPInterfaceProperties adapterProperties = adapter.GetIPProperties();
    IPAddressCollection dnsServers = adapterProperties.DnsAddresses;
    if (dnsServers.Count > 0)
    {

        Console.WriteLine("Adapter Id .... : " + adapter.Id);
        Console.WriteLine("Adapter Description .... : " + adapter.Description);
        Console.WriteLine("Adapter Name .... : " + adapter.Name);
Console.WriteLine("Network Interface Type .... : " + adapter.NetworkInterfaceType.ToString());
        Console.WriteLine("Adapter Speed .... : " + adapter.Speed);
        Console.WriteLine("OperationalStatus .... : " + adapter.OperationalStatus);
        Console.WriteLine("Adapter SupportsMulticast .... : " + adapter.SupportsMulticast);

        }
    }

请建议。

0 个答案:

没有答案