.net6,.net core获取服务器上所有网卡的IP地址 电脑版发表于:2022/12/27 9:40 代码如下: ``` //获取服务器上所有网卡的IP地址 NetworkInterface[] networks = NetworkInterface.GetAllNetworkInterfaces(); string serverIpAddresses = string.Empty; foreach (var network in networks) { var ipAddress = network.GetIPProperties().UnicastAddresses.Where(p => p.Address.AddressFamily == AddressFamily.InterNetwork && !IPAddress.IsLoopback(p.Address)).FirstOrDefault()?.Address.ToString(); serverIpAddresses += network.Name + ":" + ipAddress + "|"; } ```