public static string showMac() { string str = ""; foreach (NetworkAdapter adapter in NetworkAdapter.GetInstances("MACAddress IS NOT NULL")) { //DebugLog("isMACValid Net.Manufacturer = " + adapter.Manufacturer + " net.IsInstalledNull = " + adapter.IsInstalledNull.ToString() + " net.Name = " + adapter.Name.ToString()); if (IsValidNetworkAdapter(adapter)) { str = CovertMacToBase36String(adapter.MACAddress); //DebugLog("isMACValid thisBase36MAC: " + str); //if (StringType.StrCmp(base36MAC, Strings.Right(str, 5), false) == 0) //{ //} //textBox1.Text = str; //MessageBox.Show(Microsoft.VisualBasic.Strings.Right(str, 5)); //long code = 0; //Radix.Decode(str, 0x24L, ref code); //return code.ToString(); return(Strings.Right(str, 5)); } } return(""); }
private void FillAdapterLists(List <AdapterData.AdapterData> adapterList) { if (isUpdating) { hasPendingRefresh = true; return; } isUpdating = true; Application.Current.Dispatcher.Invoke(() => { if (Adapters == null) { Adapters = new ObservableCollection <AdapterData.AdapterData>(adapterList); } else { var itemsToRemove = Adapters.Where(x => !adapters.Any(c => x.networkAdapter != null && c.networkAdapter.GUID == x.networkAdapter.GUID)).ToArray(); foreach (var item in itemsToRemove) { Adapters.Remove(item); } var itemsToAdd = adapters.Where(x => !Adapters.Any(c => c.networkAdapter.GUID == x.networkAdapter.GUID)).ToArray(); foreach (var item in itemsToAdd) { Adapters.Add(item); } } var networkAdapters = NetworkAdapter.GetInstances().Cast <NetworkAdapter>().ToList(); var interfaces = NetworkInterface.GetAllNetworkInterfaces().ToList(); foreach (var item in Adapters) { item.Update(networkAdapters, interfaces); item.NotifyPropertyChanged(nameof(item.NetEnabled)); } if (SelectedAdapter == null) { SelectedAdapter = Adapters.FirstOrDefault(x => x.NetEnabled); if (SelectedAdapter == null) { SelectedAdapter = Adapters.FirstOrDefault(); } } }); isUpdating = false; if (hasPendingRefresh) { hasPendingRefresh = false; FillAdapterLists(AdapterDataExtensions.GetAdapters(ShowOnlyPhysical)); } }
public Tui() { var scope = Wmi.GetScope(); var enumOptions = new EnumerationOptions { EnsureLocatable = true }; _system = ComputerSystem.GetInstances(scope, enumOptions).Cast <ComputerSystem>().FirstOrDefault(); _processor = Processor.GetInstances(scope, enumOptions).Cast <Processor>().FirstOrDefault(); _networkAdapters = NetworkAdapter.GetInstances(scope, enumOptions) .Cast <NetworkAdapter>() .Where(n => n.PhysicalAdapter); _operatingSystem = new OperatingSystem0(scope); }
void NetworkChange_NetworkAddressChanged(object sender, EventArgs e) { var networkAdapters = NetworkAdapter.GetInstances().Cast <NetworkAdapter>().ToList(); var interfaces = NetworkInterface.GetAllNetworkInterfaces().ToList(); if (Current != null) { Current.Update(SelectedAdapter, networkAdapters, interfaces); } foreach (var item in Adapters) { item.Update(networkAdapters, interfaces); item.NotifyPropertyChanged("NetEnabled"); } }
internal static List <AdapterData> GetAdapters(bool GetOnlyPhysicalAdapters = true) { var data = new List <AdapterData>(); var adapters = NetworkAdapter.GetInstances().Cast <NetworkAdapter>().Where(z => !GetOnlyPhysicalAdapters || z.PhysicalAdapter); var interfaces = NetworkInterface.GetAllNetworkInterfaces(); foreach (var item in adapters) { var newAdapterData = new AdapterData { networkAdapter = item, networkInterface = interfaces.FirstOrDefault(z => z.Id == item.GUID) }; data.Add(newAdapterData); } return(data); }
public void Update(AdapterData adapter, List <NetworkAdapter> adapters, List <NetworkInterface> interfaces) { try { // Refresh data if (adapters == null) { adapters = NetworkAdapter.GetInstances().Cast <NetworkAdapter>().ToList(); } if (interfaces == null) { interfaces = NetworkInterface.GetAllNetworkInterfaces().ToList(); } adapter.Update(adapters, interfaces); Name = adapter.networkAdapter.Name; Mac = adapter.networkAdapter.MACAddress; Status = adapter.GetStatusText(); IsActive = adapter.networkAdapter.ConfigManagerErrorCode != NetworkAdapter.ConfigManagerErrorCodeValues.This_device_is_disabled_; HasAdapter = adapter.networkInterface != null; if (adapter.networkInterface == null) { return; } var networkInterfaceIPProperties = adapter.networkInterface.GetIPProperties(); var networkInterfaceIPv4Properties = networkInterfaceIPProperties.GetIPv4Properties(); if (adapter.networkAdapter.NetConnectionStatus == 2) { Speed = (adapter.networkAdapter.Speed / (1000 * 1000)).ToString("F1") + " Mbps"; } else { Speed = null; } IsDhcpEnabled = networkInterfaceIPv4Properties.IsDhcpEnabled; WinsEnabled = networkInterfaceIPv4Properties.UsesWins.ToActiveText(); // Ignore loop-back addresses & IPv6 var tempIp = string.Empty; foreach (var item in networkInterfaceIPProperties.UnicastAddresses .Where(z => z.Address.AddressFamily == AddressFamily.InterNetwork) .Where(z => !IPAddress.IsLoopback(z.Address)) .Where(z => z.IPv4Mask != null && z.Address != null)) { tempIp += string.Format(@"{0}\{1}{2}", item.Address, item.IPv4Mask, Environment.NewLine); } Ip = tempIp.Trim(); var tempDnsServers = string.Empty; foreach (var item in networkInterfaceIPProperties.DnsAddresses.Where(z => z.AddressFamily == AddressFamily.InterNetwork)) { tempDnsServers += item + Environment.NewLine; } DnsServers = tempDnsServers.Trim(); var tempGateways = string.Empty; foreach (var item in networkInterfaceIPProperties.GatewayAddresses) { tempGateways += item.Address + Environment.NewLine; } Gateways = tempGateways.Trim(); var TempDhcpServers = string.Empty; foreach (var item in networkInterfaceIPProperties.DhcpServerAddresses.Where(z => z.AddressFamily == AddressFamily.InterNetwork)) { TempDhcpServers += item + Environment.NewLine; } DhcpServers = TempDhcpServers.Trim(); var tempWinsServers = string.Empty; foreach (var item in networkInterfaceIPProperties.WinsServersAddresses.Where(z => z.AddressFamily == AddressFamily.InterNetwork)) { tempWinsServers += item + Environment.NewLine; } WinsServers = tempWinsServers.Trim(); var tempAnyCast = string.Empty; foreach (var item in networkInterfaceIPProperties.AnycastAddresses.Where(z => z.Address.AddressFamily == AddressFamily.InterNetwork)) { tempAnyCast += item.Address + Environment.NewLine; } AnyCast = tempAnyCast.Trim(); var tempMulticast = string.Empty; foreach (var item in networkInterfaceIPProperties.MulticastAddresses.Where(z => z.Address.AddressFamily == AddressFamily.InterNetwork)) { tempMulticast += item.Address + Environment.NewLine; } Multicast = tempMulticast.Trim(); } catch (Exception ex) { SimpleMessenger.Default.SendMessage("ErrorText", ex.Message); } }