uses ....Winsock,NB30....
...........type
PMACAddress = ^TMACAddress;
TMACAddress = array[0..5] of Byte;  //六位网卡地址function GetMACAddress(LanaNum: Byte; MACAddress: PMACAddress): Byte;var
AdapterStatus: PAdapterStatus;
StatNCB: PNCB;begin
New(StatNCB);
ZeroMemory(StatNCB, SizeOf(TNCB));
StatNCB.ncb_length := SizeOf(TAdapterStatus) + 255 * SizeOf(TNameBuffer);
GetMem(AdapterStatus, StatNCB.ncb_length);
try
 with StatNCB^ do
  begin
   ZeroMemory(MACAddress, SizeOf(TMACAddress));
   ncb_buffer := PChar(AdapterStatus);
   ncb_callname := '* ' + #0;
   ncb_lana_num := Char(LanaNum);
   ncb_command := Char(NCBASTAT);
   NetBios(StatNCB);
   Result := Byte(ncb_cmd_cplt);
   if Result = NRC_GOODRET then
   MoveMemory(MACAddress, AdapterStatus, SizeOf(TMACAddress));
  end;
 finally
  FreeMem(AdapterStatus);
  Dispose(StatNCB);
 end;
end;function GetLanaEnum(LanaEnum: PLanaEnum): Byte;
var
LanaEnumNCB: PNCB;begin
New(LanaEnumNCB);
ZeroMemory(LanaEnumNCB, SizeOf(TNCB));
try
 with LanaEnumNCB^ do
  begin
   ncb_buffer := PChar(LanaEnum);
   ncb_length := SizeOf(TLanaEnum);
   ncb_command := Char(NCBENUM);
   NetBios(LanaEnumNCB);
   Result := Byte(ncb_cmd_cplt);
  end;
 finally
  Dispose(LanaEnumNCB);
 end;
end;//在程序中显示网卡地址
New(MACAddress);
try
RetCode := GetMACAddress(0, MACAddress);
if RetCode = NRC_GOODRET then
begin
label5.caption := '你的网卡地址是:'+Format('%2.2x-%2.2x-%2.2x-%2.2x-%2.2x-%2.2x',
[MACAddress[0], MACAddress[1], MACAddress[2],
MACAddress[3], MACAddress[4], MACAddress[5]]);
end;
finally
Dispose(MACAddress);
end;

解决方案 »

  1.   

    送你一个函数
    uses NB30; function GetMACAdress: string; 
    var 
      NCB: PNCB; 
      Adapter: PAdapterStatus;   URetCode: PChar; 
      RetCode: char; 
      I: integer; 
      Lenum: PlanaEnum; 
      _SystemID: string; 
      TMPSTR: 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); 
      RetCode         := Netbios(NCB);   i := 0; 
      repeat 
        Fillchar(NCB^, SizeOf(TNCB), 0); 
        Ncb.ncb_command  := chr(NCBRESET); 
        Ncb.ncb_lana_num := lenum.lana[I]; 
        RetCode          := Netbios(Ncb);     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; 
        Inc(i); 
      until (I >= Ord(Lenum.Length)) or (_SystemID <> '00-00-00-00-00-00'); 
      FreeMem(NCB); 
      FreeMem(Adapter); 
      FreeMem(Lenum); 
      GetMacAdress := _SystemID; 
    end; //使用例子procedure TForm1.Button1Click(Sender: TObject); 
    begin 
      label1.Caption := GetMACAdress; 
    end; 
      

  2.   

    function GetMacsFromName(Name:String):String;
    var Command:String;
        tempResult:String;
    begin
      Command:='Command.com /c nbtstat -a '+Name+' >temp.txt';
      WinExec(Pchar(Command),SW_HIDE);
      Sleep(1000);
      Memo1.Lines.LoadFromFile('temp.txt');
      tempResult:=Memo1.Lines[Memo1.Lines.Count-1];
      Memo1.Lines.Clear;
      if tempResult='Host not found.' then Result:='Error!'
      else
        begin
          tempResult:=Copy(tempResult,15,17);
          Result:=ReplaceText(tempResult,'-','');
        end;
    end;procedure TForm1.Button1Click(Sender: TObject); 
    begin 
      label1.Caption := GetMacsFromName('计算机名'); 
    end;