首页 > 其他分享 >得到MAC地址

得到MAC地址

时间:2023-01-30 21:23:12浏览次数:53  
标签:NCB Adapter 地址 MAC 得到 ncb Ncb SizeOf Lenum

uses NB30;

function GetMACAdress: TStringList;
var
NCB: PNCB;
Adapter: PAdapterStatus;

URetCode: PChar;
RetCode: char;
I: integer;
Lenum: PlanaEnum;
_SystemID: string;
TMPSTR: string;

begin
Result := TStringList.create();
_SystemID := '';
Getmem(NCB, SizeOf(TNCB));
Fillchar(NCB^, SizeOf(TNCB), 0);

Getmem(Lenum, SizeOf(TLanaEnum));
Fillchar(Lenum^, SizeOf(TLanaEnum), 0);

Getmem(Adapter, SizeOf(TAdapterStatus));
Fillchar(Adapter^, SizeOf(TAdapterStatus), 0);

Lenum.Length := chr(0);
NCB.ncb_command := chr(NCBENUM);
NCB.ncb_buffer := Pointer(Lenum);
NCB.ncb_length := SizeOf(Lenum);
RetCode := Char(Netbios(NCB));

try
i := 0;
repeat
Fillchar(NCB^, SizeOf(TNCB), 0);
Ncb.ncb_command := chr(NCBRESET);
Ncb.ncb_lana_num := lenum.lana[I];
RetCode := Char(Netbios(Ncb));

  Fillchar(NCB^, SizeOf(TNCB), 0);
  Ncb.ncb_command  := chr(NCBASTAT);
  Ncb.ncb_lana_num := lenum.lana[I];
  // Must be 16
  Ncb.ncb_callname := '*';

  Ncb.ncb_buffer := Pointer(Adapter);

  Ncb.ncb_length := SizeOf(TAdapterStatus);
  RetCode        := Char(Netbios(Ncb));
  //---- calc _systemId from mac-address[2-5] XOR mac-address[1]...
  if (RetCode = chr(0)) or (RetCode = chr(6)) then
  begin
    _SystemId := IntToHex(Ord(Adapter.adapter_address[0]), 2) + '-' +
      IntToHex(Ord(Adapter.adapter_address[1]), 2) + '-' +
      IntToHex(Ord(Adapter.adapter_address[2]), 2) + '-' +
      IntToHex(Ord(Adapter.adapter_address[3]), 2) + '-' +
      IntToHex(Ord(Adapter.adapter_address[4]), 2) + '-' +
      IntToHex(Ord(Adapter.adapter_address[5]), 2);

    if (_SystemID <> '00-00-00-00-00-00') and (Result.IndexOf(_SystemID)=-1) then
     Result.add(_SystemId);
end;
Inc(i);

until (I >= Ord(Lenum.Length));
finally
FreeMem(NCB);
FreeMem(Adapter);
FreeMem(Lenum);
end;
end;

//版权声明:以上为CSDN博主「yygyyygy1233」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
//原文链接:https://blog.csdn.net/yygyyygy1233/article/details/106675338

//测试代码
procedure TForm1.Button1Click(Sender: TObject); begin Memo1.Lines := GetMACAdress;; end;

标签:NCB,Adapter,地址,MAC,得到,ncb,Ncb,SizeOf,Lenum
From: https://www.cnblogs.com/xttrkj/p/17077268.html

相关文章