NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface networkInterface in networkInterfaces)
{
if (networkInterface.OperationalStatus == OperationalStatus.Up &&
(networkInterface.NetworkInterfaceType == NetworkInterfaceType.Ethernet ||
networkInterface.NetworkInterfaceType == NetworkInterfaceType.Wireless80211))
{
IPInterfaceProperties ipProperties = networkInterface.GetIPProperties();
foreach (UnicastIPAddressInformation ipInfo in ipProperties.UnicastAddresses)
{
if (ipInfo.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
return $"Локальный IP-адрес: {ipInfo.Address}";
}
}
}
}