zoukankan      html  css  js  c++  java
  • 取得所有网卡的MAC地址,包括禁用的

    先在nuget包中添加System.Management.Automation引用。

    然后下面就是代码了。

    using System;
    using System.Collections.ObjectModel;
    using System.Management.Automation;
    using System.Text;
    using System.Windows.Forms;

    namespace GetMAC
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                StringBuilder sb = new StringBuilder();
                using (PowerShell PowerShellInstance = PowerShell.Create())
                {
                    PowerShellInstance.AddCommand("Get-NetAdapter");

                    Collection<PSObject> PSOutput = PowerShellInstance.Invoke();

                    foreach (PSObject result in PSOutput)
                    {
                        sb.Append(result.Members["PermanentAddress"].Value + " ");
                    }
                }
                textBox1.Text = sb.ToString();
            }

        }
    }

  • 相关阅读:
    神奇的条件注解-Spring Boot自动配置的基石
    Spring 注解配置原理
    元注解之@Repeatable
    MyBatis批量操作
    MapperScannerConfigurer源码解析
    Spring包扫描机制详解
    SqlSessionTemplate源码解析
    DataSourceUtils源码分析
    Spring事务源码分析
    多核CPU
  • 原文地址:https://www.cnblogs.com/dengxi/p/7844687.html
Copyright © 2011-2022 走看看