Delphi ile bir bilgisayarın MAC adresini bulma

'Diğer Programlama Dilleri' forumunda acemihacker tarafından 3 Temmuz 2018 tarihinde açılan konu

  1. acemihacker

    acemihacker Ötüken Yolcusu Bronz Üye

    Mesaj:
    205
    Beğeniler:
    74
    Cinsiyet:
    Erkek
    Kod:
    ses NB30;
    
    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;
    
    // usage
    procedure TForm1.Button1Click(SENDER: TObject);
    begin
      ShowMessage(GetMACAddress);
    end;
     
Yükleniyor...

Bu Sayfayı Paylaş