Identifying active network interface

后端 未结 5 1930
走了就别回头了
走了就别回头了 2020-12-01 02:30

In a .NET application, how can I identify which network interface is used to communicate to a given IP address?

I am running on workstations with multiple network in

5条回答
  •  悲哀的现实
    2020-12-01 02:47

    At least you can start with that, giving you all addresses from dns for the local machine.

    IPHostEntry hostEntry = Dns.GetHostEntry(Environment.MachineName);
    
    foreach (System.Net.IPAddress address in hostEntry.AddressList)
    {
        Console.WriteLine(address);
    }
    

提交回复
热议问题