using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.NetworkInformation; using System.Runtime.InteropServices; namespace SHARP { internal class BSSID { [DllImport("iphlpapi.dll")] private static extern int SendARP( int destIp, int srcIP, byte[] macAddr, ref uint physicalAddrLen); public static string GetBSSID() { byte[] macAddr = new byte[6]; uint length = (uint) macAddr.Length; try { if (BSSID.SendARP(BitConverter.ToInt32(IPAddress.Parse(BSSID.GetDefaultGateway()).GetAddressBytes(), 0), 0, macAddr, ref length) != 0) return "unknown"; string[] strArray = new string[(int) length]; for (int index = 0; (long) index < (long) length; ++index) strArray[index] = macAddr[index].ToString("x2"); return string.Join(":", strArray); } catch (Exception ex) { Console.WriteLine((object) ex); } return "Failed"; } public static string GetDefaultGateway() { try { return ((IEnumerable) NetworkInterface.GetAllNetworkInterfaces()).Where((Func) (n => n.OperationalStatus == OperationalStatus.Up)).Where((Func) (n => n.NetworkInterfaceType != NetworkInterfaceType.Loopback)).SelectMany((Func>) (n => { IPInterfaceProperties ipProperties = n.GetIPProperties(); return ipProperties == null ? (IEnumerable) null : (IEnumerable) ipProperties.GatewayAddresses; })).Select((Func) (g => g?.Address)).Where((Func) (a => a != null)).FirstOrDefault().ToString(); } catch (Exception ex) { Console.WriteLine((object) ex); } return "Unknown"; } } }