Ver Mensaje Individual
  #6  
Antiguo 06-07-2012
barakuda barakuda is offline
Miembro
 
Registrado: mar 2010
Posts: 79
Reputación: 15
barakuda Va por buen camino
Gracias por responder luisgutierrezb hice lo que me comentabas y sigue el mismo problema, es mas como veras en el código incluyo el edit pero como si nada ni un error ni nada.
Es raro ya que siempre me muestra la mac local, es como si pasara de mi ya que al picar al botón lo único que debería hacer es asignar el resultado de la consulta a la función "ObtenerMAC", a la etiqueta label1.
En definitiva parece que no le guste el que en (IP) se le asigne algo indeterminado y prefiera un fijo ('143.1.14.202')

Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, winsock,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

type
  PULONG = ^ULONG;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function SendARP(DestIP,SrcIP: in_addr; pMacAddr,PhyAddrLen: PULONG): DWORD;
  stdcall; external 'iphlpapi.dll' name 'SendARP';

function ObtenerMAC(IP: AnsiString): AnsiString;
var
  i: Integer;
  dwRetVal: DWORD;
  DestIp, SrcIp: in_addr;
  MacAddr: array[0..1] of ULONG;
  PhysAddrLen: ULONG;
  PhysAddr: PByte;
begin
    DestIp.S_addr:= 0;
    SrcIp.S_addr:= 0;
    PhysAddrLen:= 6;
    DestIp.S_addr:= inet_addr(@IP);

    dwRetVal:= SendARP(DestIp, SrcIp, @MacAddr, @PhysAddrLen);

    Result:= EmptyStr;
    if dwRetVal = NO_ERROR then
    begin
      PhysAddr:= PByte(@MacAddr);
      for i := 1 to Sizeof(MacAddr)-2 do
      begin
        if Result= EmptyStr then
          Result:= IntToHex(PhysAddr^,2)
        else
          Result:= Result + '-' + IntToHex(PhysAddr^,2);
        inc(PhysAddr);

      end;
    end;
    end;

procedure TForm1.Button1Click(Sender: TObject);
begin
label1.Caption:=ObtenerMAC(form1.Edit1.Text);
end;

end.
Responder Con Cita