xxm0720 2017-12-04 01:53 采纳率: 0%
浏览 1890

C# 通过ip获取mac地址

想要获取登录页面是设备的ip和mac地址,ip我知道怎么获取,但是mac地址怎么获取,各位大神如何解决?

  • 写回答

1条回答 默认 最新

  • 青柠928 2017-12-04 02:15
    关注

    publicstatic List GetMacByIPConfig()
    {
    List macs =new List();
    ProcessStartInfo startInfo = new ProcessStartInfo("ipconfig", "/all");
    startInfo.UseShellExecute = false;
    startInfo.RedirectStandardInput = true;
    startInfo.RedirectStandardOutput = true;
    startInfo.RedirectStandardError = true;
    startInfo.CreateNoWindow = true;
    Process p = Process.Start(startInfo);
    //截取输出流
    StreamReader reader = p.StandardOutput;
    string line = reader.ReadLine();

    while (!reader.EndOfStream)
    {
    if (!string.IsNullOrEmpty(line))
    {
    line = line.Trim();

      if (line.StartsWith("Physical Address"))
      {
        macs.Add(line);
      }
    }
    
    line = reader.ReadLine();
    

    }

    //等待程序执行完退出进程
    p.WaitForExit();
    p.Close();
    reader.Close();

    return macs;
    }

    评论

报告相同问题?

悬赏问题

  • ¥15 vhdl+MODELSIM
  • ¥20 simulink中怎么使用solve函数?
  • ¥30 dspbuilder中使用signalcompiler时报错Error during compilation: Fitter failed,求解决办法
  • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题