获取网卡MAC地址

2012-06-19 09:29:37 作者:yydhw 来源: 浏览次数:0 网友评论 0


function GetAdapterInfo(Lana: Char): String;
var 
 Adapter: TAdapterStatus;
 NCB: TNCB;
begin 
 FillChar(NCB, SizeOf(NCB), 0);
 NCB.ncb_command := Char(NCBRESET);
 NCB.ncb_lana_num := Lana;
 if Netbios(@NCB) <> Char(NRC_GOODRET) then
 begin
   Result := 'mac not found';
   Exit; 
 end;

 FillChar(NCB, SizeOf(NCB), 0);
 NCB.ncb_command := Char(NCBASTAT);
 NCB.ncb_lana_num := Lana;
 NCB.ncb_callname := '*';

 FillChar(Adapter, SizeOf(Adapter), 0);
 NCB.ncb_buffer := @Adapter;
 NCB.ncb_length := SizeOf(Adapter);
 if Netbios(@NCB) <> Char(NRC_GOODRET) then
 begin
   Result := 'mac not found';
   Exit;
 end;
 Result :=
   IntToHex(Byte(Adapter.adapter_address[0]), 2) + '-' +
   IntToHex(Byte(Adapter.adapter_address[1]), 2) + '-' +
   IntToHex(Byte(Adapter.adapter_address[2]), 2) + '-' +
   IntToHex(Byte(Adapter.adapter_address[3]), 2) + '-' +
   IntToHex(Byte(Adapter.adapter_address[4]), 2) + '-' +
   IntToHex(Byte(Adapter.adapter_address[5]), 2);
end;


function GetMACAddress: string;
var 
 AdapterList: TLanaEnum;
 NCB: TNCB;
begin 
 FillChar(NCB, SizeOf(NCB), 0);
 NCB.ncb_command := Char(NCBENUM);
 NCB.ncb_buffer := @AdapterList;
 NCB.ncb_length := SizeOf(AdapterList);
 Netbios(@NCB);
 if Byte(AdapterList.length) > 0 then
   Result := GetAdapterInfo(AdapterList.lana[0])
 else
  Result := 'mac not found';
end;


关键词:获取网卡MAC

[错误报告] [推荐] [收藏] [打印] [关闭] [返回顶部]

最新十条评论
  • 验证码:

最新图片文章

赞助商广告2

最新文章

日文章点击排行

周文章点击排行

月文章点击排行