[delphi] 맥어드레스 가져오기(GetMACAdress2)

반응형
반응형

function GetMACAdress2: string;
var
    NCB: PNCB;
    Adapter: PAdapterStatus;
    RetCode: char;
    I: Integer;
    Lenum: PlanaEnum;
    _SystemID: string;
begin
    Result := '';
    _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);

    i := 0;
    //    Repeat
    Fillchar(NCB^ ,Sizeof(TNCB) ,0);
    Ncb.ncb_command := chr(NCBRESET);
    Ncb.ncb_lana_num := lenum.lana[I];

    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 := 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);
    end;
    FreeMem(NCB);
    FreeMem(Adapter);
    FreeMem(Lenum);
    GetMacAdress2 := _SystemID;
end;

<

 

반응형

'Developers > Delphi[델파이]' 카테고리의 다른 글

[Delphi] TIdHTTP 통해 https 통신  (85) 2019.09.19
Undeclared identifier 에러 발생 할 때  (1) 2019.09.16
[delphi] 날짜형식  (0) 2019.09.16

댓글