如何使用Delphi获取网卡的MAC地址? [英] How do I get the MAC address of a network card using Delphi?

查看:232
本文介绍了如何使用Delphi获取网卡的MAC地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据标题 - 任何人都可以帮助我吗?

As per title - can anyone help me?

推荐答案

获取Microsoft IP Helper库的JEDI转换, a href =http://www.delphi-jedi.org/apilibrary.html =noreferrer> Project JEDI API头文件库 - 该文件是IPHlpAPI.zip。打开文件包,你需要IpTypes.pas和IpHlpApi.pas。那么你可以使用这样的东西:

Get the JEDI conversion of the Microsoft IP Helper Library from the Project JEDI API Header Library - the file is IPHlpAPI.zip. Unpack the files, you need IpTypes.pas and IpHlpApi.pas. Then you can use something like this:

procedure TForm1.Button1Click(Sender: TObject);
var
  NumInterfaces: Cardinal;
  AdapterInfo: array of TIpAdapterInfo;
  OutBufLen: ULONG;
  i: integer;
begin
  GetNumberOfInterfaces(NumInterfaces);
  SetLength(AdapterInfo, NumInterfaces);
  OutBufLen := NumInterfaces * SizeOf(TIpAdapterInfo);
  GetAdaptersInfo(@AdapterInfo[0], OutBufLen);

  Memo1.Lines.Clear;
  for i := 0 to NumInterfaces - 1 do begin
    Memo1.Lines.Add(Format('%.2x:%.2x:%.2x:%.2x:%.2x:%.2x',
      [AdapterInfo[i].Address[0], AdapterInfo[i].Address[1],
       AdapterInfo[i].Address[2], AdapterInfo[i].Address[3],
       AdapterInfo[i].Address[4], AdapterInfo[i].Address[5]]));
  end;
end;

(所有错误处理省略,您应该添加它当然)。

(All error handling omitted, you should add it of course.)

这篇关于如何使用Delphi获取网卡的MAC地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆