Delphi - Como leer el codigo MAC

 
Vista:

Como leer el codigo MAC

Publicado por Irreal (69 intervenciones) el 28/09/2006 16:40:56
¿Como puedo leer el codigo de MAC de la targeta de red.?

He conseguido el siguiente codigo, pero eventualmente cambnia el numero, lo cual me hace sospecha de su validez. ¿ Alguien sabe leer el codigo MAC, tal y como lo muestra la instrucción D.O.S. 'ipconfig /All'?

He codigo que no me funciona es :

procedure TForm1.Button1Click(Sender: TObject);
Type
// Una estructura que une el estado del adaptador
// con una matriz de estructuras TNameBuffer
ASTAT = record
adapt: TAdapterStatus;
NameBuff: Array[0..29] Of TNameBuffer;
end;
Var
Adaptador: ASTAT;
Ncb: TNCB;
Nombre: String;
DatosSocket: WSAData;
BloqueIP: PHostEnt;
DirIP: in_addr;
begin
With Ncb Do // Inicializamos la estructura para ejecutar
Begin // el comando NCBSTAT
ncb_command := char(NCBASTAT);
ncb_lana_num := char(0); // asumimos que sólo hay un adaptador
ncb_callname := '*'; // y no facilitamos nombre
ncb_buffer := @Adaptador; // dirección de la estructura para obtener
ncb_length := sizeof(Adaptador); // los datos devueltos
End;

Netbios(@Ncb); // Llamada a NetBios

// Mostramos los datos
With Adaptador.adapt Do
ShowMessage('La dirección MAC es: ' +
IntToHex(Integer(adapter_address[0]), 2) +
IntToHex(Integer(adapter_address[1]), 2) +
IntToHex(Integer(adapter_address[2]), 2) +
IntToHex(Integer(adapter_address[3]), 2) +
IntToHex(Integer(adapter_address[4]), 2) +
IntToHex(Integer(adapter_address[5]), 2));

WSAStartup($0101, DatosSocket); // Inicializamos Windows sockets
SetLength(Nombre, MAX_PATH); // y obtenemos el nombre de nuestro equipo
gethostname(PChar(Nombre), MAX_PATH);
// que usamos para obtener un bloque de información sobre IP
BloqueIP := gethostbyname(PChar(Nombre));
// del cual recuperamos la dirección
CopyMemory(@DirIP, (BloqueIP^).h_addr_list^, BloqueIP.h_length);
ShowMessage(inet_ntoa(DirIP)); // y la mostramos
ShowMessage('Nombre del PC en la red: ' + nombre);
end;
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Como leer el codigo MAC

Publicado por Coleta (1 intervención) el 10/10/2006 02:17:21
Pos yo tirando de un truco lo he montado asi.. Es un poco feo, diria yo, pero aporta una consola de MS-DOS, y la MAC es correcta. Necesitais una form, un button, un memo y un label donde sacará la MAC. Espero que os sirva. Salu2 d Coleta.


procedure TForm1.Button3Click(Sender: TObject);
procedure RunDosInMemo(Que:String;EnMemo:TMemo);
const
CUANTOBUFFER = 2000;
var
Seguridades : TSecurityAttributes;
PaLeer,PaEscribir : THandle;
start : TStartUpInfo;
ProcessInfo : TProcessInformation;
Buffer : Pchar;
BytesRead : DWord;
CuandoSale : DWord;
begin
with Seguridades do
begin
nlength := SizeOf(TSecurityAttributes);
binherithandle := true;
lpsecuritydescriptor := nil;
end;
{Creamos el pipe...}
if Createpipe (PaLeer, PaEscribir, @Seguridades, 0) then
begin
Buffer := AllocMem(CUANTOBUFFER + 1);
FillChar(Start,Sizeof(Start),#0);
start.cb := SizeOf(start);
start.hStdOutput := PaEscribir;
start.hStdInput := PaLeer;
start.dwFlags := STARTF_USESTDHANDLES +
STARTF_USESHOWWINDOW;
start.wShowWindow := SW_HIDE;

if CreateProcess(nil,
PChar(Que),
@Seguridades,
@Seguridades,
true,
NORMAL_PRIORITY_CLASS,
nil,
nil,
start,
ProcessInfo)
then
begin
{Espera a que termine la ejecucion}
repeat
CuandoSale := WaitForSingleObject( ProcessInfo.hProcess,100);
Application.ProcessMessages;
until (CuandoSale <> WAIT_TIMEOUT);
{Leemos la Pipe}
repeat
BytesRead := 0;
{Llenamos un troncho de la pipe, igual a nuestro buffer}
ReadFile(PaLeer,Buffer[0],CUANTOBUFFER,BytesRead,nil);
{La convertimos en una string terminada en cero}
Buffer[BytesRead]:= #0;
{Convertimos caracteres DOS a ANSI}
OemToAnsi(Buffer,Buffer);
EnMemo.Text := EnMemo.text + String(Buffer);
// **** Busco alguna cadena conocida ****
if pos('sica. .',String(buffer))<>0 then // **** Aqui está la MAC *****
label1.Caption:='copy(String(buffer),pos('sica',String(buffer))+24,17);

until (BytesRead < CUANTOBUFFER);
end;
FreeMem(Buffer);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
CloseHandle(PaLeer);
CloseHandle(PaEscribir);
end;
end;

begin
RunDosInMemo('ipconfig /all',Memo1);
end;
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar