function nbgetmac:string;
  function hexbl(by:byte):string;
   begin
     result:=format('%x',[by]);
     if length(result)<2 then
        result:='0'+result;
   end;
var ncb:Tncb;
adapter:Tadapterstatus;
lanaenum:Tlanaenum;
i,j:integer;
str:string;
begin
result:='';
zeromemory(@ncb,sizeof(ncb));
ncb.ncb_command:=chr(ncbenum);
netbios(@ncb);
ncb.ncb_buffer:=@lanaenum;
ncb.ncb_length:=sizeof(lanaenum);
ncb.ncb_command:=chr(ncbenum);
netbios(@ncb);
for i:=0 to ord(lanaenum.length)-1 do
  begin
    zeromemory(@ncb,sizeof(ncb));
    ncb.ncb_command:=chr(ncbreset);
    ncb.ncb_lana_num:=lanaenum.lana[i];
    netbios(@ncb);
    zeromemory(@ncb,sizeof(ncb));
    ncb.ncb_command:=chr(ncbastat);
    ncb.ncb_lana_num:=lanaenum.lana[i];
    strpcopy(ncb.ncb_callname,'*');
    ncb.ncb_buffer:=@adapter;
    ncb.ncb_length:=sizeof(adapter);
    netbios(@ncb);
    str:='';
    for j:=0 to 5 do
     str:=str+hexbl(byte(adapter.adapter_address[j]));
    result:=str;
    break;
  end;
end;

解决方案 »

  1.   

    来自:Project JEDI Code Library (JCL)上的一段源代码function GetMacAddresses(const Machine: string; const Addresses: TStrings): Integer;
    var
      NCB: TNCB;
      Enum: TLanaEnum;
      I, L, NameLen: Integer;
      Adapter: ASTAT;
      MachineName: string;
    begin
      Result := -1;
      Addresses.Clear;
      MachineName := UpperCase(Machine);
      if MachineName = '' then
        MachineName := '*';
      NameLen := Length(MachineName);
      L := NCBNAMSZ - NameLen;
      if L > 0 then
      begin
        SetLength(MachineName, NCBNAMSZ);
        FillChar(MachineName[NameLen + 1], L, ' ');
      end;
      FillChar(NCB, SizeOf(NCB), #0);
      NCB.ncb_command := NCBENUM;
      NCB.ncb_buffer := Pointer(@Enum);
      NCB.ncb_length := SizeOf(Enum);
      if NetBios(@NCB) = NRC_GOODRET then
      begin
        Result := Enum.Length;
        for I := 0 to Ord(Enum.Length) - 1 do
        begin
          FillChar(NCB, SizeOf(NCB), #0);
          NCB.ncb_command := NCBRESET;
          NCB.ncb_lana_num := Enum.lana[I];
          if NetBios(@NCB) = NRC_GOODRET then
          begin
            FillChar(NCB, SizeOf(NCB), #0);
            NCB.ncb_command := NCBASTAT;
            NCB.ncb_lana_num := Enum.lana[I];
            Move(MachineName[1], NCB.ncb_callname, SizeOf(NCB.ncb_callname));
            NCB.ncb_buffer := PChar(@Adapter);
            NCB.ncb_length := SizeOf(Adapter);
            if NetBios(@NCB) = NRC_GOODRET then
              Addresses.Add(AdapterToString(Adapter.adapt));
          end;
        end;
      end;
    end;function GetLocalComputerName: string;
    var
      Count: DWORD;
    begin
      Count := MAX_COMPUTERNAME_LENGTH + 1;
      // set buffer size to MAX_COMPUTERNAME_LENGTH + 2 characters for safety
      SetLength(Result, Count);
      Win32Check(GetComputerName(PChar(Result), Count));
      StrResetLength(Result);
    end;调用:GetMacAddresses(GetLocalComputerName, ListBox.Items);
      

  2.   

    还少了一个函数:)
    procedure StrResetLength(var S: AnsiString);
    begin
      SetLength(S, StrLen(PChar(S)));
    end;
      

  3.   

    PLanaEnum = ^TLanaEnum;
      TLanaEnum = record
        length: Byte;
        lana: array [0..MAX_LANA] of Byte;
      end;type
      PNCB = ^TNCB;
      TNCBPostProc = procedure (P: PNCB); stdcall;
      TNCB = record
        ncb_command: Byte;
        ncb_retcode: Byte;
        ncb_lsn: Byte;
        ncb_num: Byte;
        ncb_buffer: PChar;
        ncb_length: Word;
        ncb_callname: array [0..NCBNAMSZ - 1] of Char;
        ncb_name: array [0..NCBNAMSZ - 1] of Char;
        ncb_rto: Byte;
        ncb_sto: Byte;
        ncb_post: TNCBPostProc;
        ncb_lana_num: Byte;
        ncb_cmd_cplt: Byte;
        ncb_reserve: array [0..9] of Char;
        ncb_event: THandle;
      end;ASTAT = record
        adapt: TAdapterStatus;
        namebuf: array [0..29] of TNameBuffer;
      end;const
      NCBNAMSZ    = 16; 
      NRC_GOODRET = $00; function NetBios(P: PNCB): Byte;
    begin
      if InitNetbios then
        Result := _NetBios(P)
      else
        Result := 1; // anything other then NRC_GOODRET will do
    end;
    function AdapterToString(Adapter: TAdapterStatus): string;
    begin
      with Adapter do
        Result := Format('%2.2x-%2.2x-%2.2x-%2.2x-%2.2x-%2.2x', [
          Integer(adapter_address[0]), Integer(adapter_address[1]),
          Integer(adapter_address[2]), Integer(adapter_address[3]),
          Integer(adapter_address[4]), Integer(adapter_address[5])]);
    end;
    再好差不多了吧