i have this linq method how get all machine network card properties and i don't want to use linq, can i have some help to convert it and not using Linq ?
public NetworkAdapter[] GetAll()
{
return (from adapter in NetworkInterface.GetAllNetworkInterfaces()
from uniCast in adapter.GetIPProperties().UnicastAddresses
where !System.Net.IPAddress.IsLoopback(uniCast.Address) && uniCast.Address.AddressFamily != AddressFamily.InterNetworkV6
let lastGatewayAddress = adapter.GetIPProperties().GatewayAddresses.LastOrDefault()
select new NetworkAdapter()
{
string Name = adapter.Name,
string ID = adapter.Id,
string Description = adapter.Description,
string IPAddress = uniCast.Address.ToString(),
string NetworkInterfaceType = adapter.NetworkInterfaceType.ToString(),
string Speed = adapter.Speed.ToString("#,##0"),
string MacAddress = getMacAddress(adapter.GetPhysicalAddress().ToString()),
string gatewayIpAddress = string.Join(" ", adapter.GetIPProperties().GatewayAddresses.Select(a => a.Address))
}).ToArray();
}
this is what i have try;
public void get()
{
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface adapter in nics)
{
Description = adapter.Description;
Name = adapter.Name;
MacAddress = adapter.GetPhysicalAddress().ToString();
IPInterfaceProperties ips = adapter.GetIPProperties();
UnicastIPAddressInformationCollection uniCast = ips.UnicastAddresses;
foreach (UnicastIPAddressInformation ipInfo in uniCast)
{
if (ipInfo.Address.AddressFamily != AddressFamily.InterNetworkV6)
{
}
}
}
}