MAC da placa de rede

Delphi

15/09/2003

alguen conhece alguma rotina de como capturar o MAC da placa de rede de uma maquina aparti de um IP.


Vqds

Vqds

Curtidas 0

Respostas

Bacalhau

Bacalhau

15/09/2003

Há um comando DOS que faz isso:

arp -a

Para guardar num arquivo

arp -a > arquivo.txt


GOSTEI 0
Vqds

Vqds

15/09/2003

Há um comando DOS que faz isso: arp -a Para guardar num arquivo arp -a > arquivo.txt



Gostaria de saber se o DELPHI tem este tipo de funcao, com a do IP da paleta indy, pois nao gostaria a ter que recorer a comandos dos para gerar um arquivo e depois ler.


GOSTEI 0
Inforplace Ltda

Inforplace Ltda

15/09/2003

function getMacEthernet : string;

Function MacAddress: string;
var Lib: Cardinal;
Func: function(GUID: PGUID): Longint; stdcall;
GUID1, GUID2: TGUID;

begin
Result := '';
Lib := LoadLibrary('rpcrt4.dll');
if Lib <> 0 then
begin
@Func := GetProcAddress(Lib, 'UuidCreateSequential');
if Assigned(Func) then
begin
if (Func(@GUID1) = 0) and
(Func(@GUID2) = 0) and
(GUID1.D4[2] = GUID2.D4[2]) and
(GUID1.D4[3] = GUID2.D4[3]) and
(GUID1.D4[4] = GUID2.D4[4]) and
(GUID1.D4[5] = GUID2.D4[5]) and
(GUID1.D4[6] = GUID2.D4[6]) and
(GUID1.D4[7] = GUID2.D4[7]) then
begin
Result :=IntToHex(GUID1.D4[2], 2) + '-' +
IntToHex(GUID1.D4[3], 2) + '-' +
IntToHex(GUID1.D4[4], 2) + '-' +
IntToHex(GUID1.D4[5], 2) + '-' +
IntToHex(GUID1.D4[6], 2) + '-' +
IntToHex(GUID1.D4[7], 2);
end;
end;
end;
end;
Begin
try
result := MacAddress;
While pos('-',result) > 0 do
delete(result,pos('-',result),1);
except
result := '';
end;

end;
GOSTEI 0
Luiz Eduardo

Luiz Eduardo

15/09/2003

Vqds, o código abaixo irá pegar o endereço mac da placa de rede ativa, muito bom esse código! segue abaixo:


uses 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; 

procedure TForm1.Button3Click(Sender: TObject);
begin
ShowMessage(GetMACAddress);
end;

GOSTEI 0
Carlos Palacios

Carlos Palacios

15/09/2003

Qual o valor do parametro devo passar na funcao function GetAdapterInfo(Lana: Char) para obter o mac?
No XE10.2 tive que aleterar a variavel LANA par a Ansichar.
se eu não passo nenhum valor, ele volta como MAC nao encontrado.
obrigado.
GOSTEI 0
POSTAR