这可能对你有所帮助
foreach(NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
{
foreach (UnicastIPAddressInformation ip in ni.GetIPProperties().UnicastAddresses)
{
if(!ip.IsDnsEligible)
{
if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
// All IP Address in the LAN
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
此代码的唯一缺点是实例返回的信息UnicastIPAddressInformation不适用于早于Windows XP的操作系统.