public async Task <List <LocalAreaConnection> > ListConnectionsAsync(CancellationToken cancel) { var adapters = new List <LocalAreaConnection>(); var count = await GetAdaptersCountAsync(); var buffer = new Memory <byte>(new byte[count * 640]); var res = await _adsClient.ReadAsync(701, 1, buffer, cancel); res.ThrowOnError(); // Slice byte array into 640 byte parts foreach (byte[] slice in buffer.ToArray().Slices(640)) { var guid = new Guid(System.Text.Encoding.UTF8.GetString(slice.Skip <byte>(8).Take <byte>(260).ToArray <byte>()).Split(new char[] { '{', '}' })[1]); var desc = ArrayHelpers.ByteArrayToString(slice.Skip <byte>(268).Take <byte>(131).ToArray <byte>()); var macAddr = new PhysicalAddress(slice.Skip <byte>(404).Take <byte>(6).ToArray <byte>()); var type = BitConverter.ToInt16(slice.Skip <byte>(416).Take <byte>(4).ToArray <byte>(), 0); var ipAddr = ArrayHelpers.ByteArrayToString(slice.Skip <byte>(432).Take <byte>(15).ToArray <byte>()); var subnet = ArrayHelpers.ByteArrayToString(slice.Skip <byte>(448).Take <byte>(15).ToArray <byte>()); var gateway = ArrayHelpers.ByteArrayToString(slice.Skip <byte>(472).Take <byte>(15).ToArray <byte>()); var dhcp = BitConverter.ToBoolean(slice.Skip <byte>(420).Take <byte>(8).ToArray <byte>(), 0); if (type == 6) // Ethernet Adapter { var adapter = new LocalAreaConnection { Description = desc, InstanceId = guid, MacAddress = macAddr, IpAddress = IPAddress.Parse(ipAddr), SubnetMask = IPAddress.Parse(subnet), Gateway = IPAddress.Parse(gateway), DHCP = dhcp }; adapters.Add(adapter); } } await adapters.ForEachAsync(async (adapter) => { // Get adapters name out of windows registry adapter.Name = await GetAdaptersNameAsync(adapter.InstanceId); }); return(adapters); }