Advertisement
HEX0x29A

GetMACAddress

Oct 16th, 2016
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.45 KB | None | 0 0
  1. uses
  2.   NB30;
  3.  
  4. function GetMACAddress: string;
  5.  
  6.   function GetAdapterInfo(Lana: AnsiChar): string;
  7.   var
  8.     Adapter: TAdapterStatus;
  9.     NCB: TNCB;
  10.   begin
  11.     FillChar(NCB, SizeOf(NCB), 0);
  12.     NCB.ncb_command := Char(NCBRESET);
  13.     NCB.ncb_lana_num := Lana;
  14.     if Netbios(@NCB) <> Char(NRC_GOODRET) then
  15.     begin
  16.       Result := 'mac not found';
  17.       Exit;
  18.     end;
  19.     FillChar(NCB, SizeOf(NCB), 0);
  20.     NCB.ncb_command := Char(NCBASTAT);
  21.     NCB.ncb_lana_num := Lana;
  22.     NCB.ncb_callname := '*';
  23.     FillChar(Adapter, SizeOf(Adapter), 0);
  24.     NCB.ncb_buffer := @Adapter;
  25.     NCB.ncb_length := SizeOf(Adapter);
  26.     if Netbios(@NCB) <> Char(NRC_GOODRET) then
  27.     begin
  28.       Result := 'mac not found';
  29.       Exit;
  30.     end;
  31.     Result := IntToHex(Byte(Adapter.adapter_address[0]), 2) + '-' + IntToHex(Byte
  32.       (Adapter.adapter_address[1]), 2) + '-' + IntToHex(Byte(Adapter.adapter_address
  33.       [2]), 2) + '-' + IntToHex(Byte(Adapter.adapter_address[3]), 2) + '-' +
  34.       IntToHex(Byte(Adapter.adapter_address[4]), 2) + '-' + IntToHex(Byte(Adapter.adapter_address
  35.       [5]), 2);
  36.   end;
  37.  
  38. var
  39.   AdapterList: TLanaEnum;
  40.   NCB: TNCB;
  41. begin
  42.   FillChar(NCB, SizeOf(NCB), 0);
  43.   NCB.ncb_command := Char(NCBENUM);
  44.   NCB.ncb_buffer := @AdapterList;
  45.   NCB.ncb_length := SizeOf(AdapterList);
  46.   Netbios(@NCB);
  47.   if Byte(AdapterList.length) > 0 then
  48.     Result := GetAdapterInfo(AdapterList.lana[0])
  49.   else
  50.     Result := 'mac not found';
  51. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement