Advertisement
Gov_777

getmac

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