Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Nov : Re: IP to MAC-address code? #2

www.cryer.info
Managed Newsgroup Archive

Re: IP to MAC-address code? #2

Subject:Re: IP to MAC-address code? #2
Posted by:"Jamie Dale" (jamie.da..@yahoo.com)
Date:Mon, 12 Nov 2007 21:32:04

Heres the 2nd version:

unit GetMacAddress2_Source;

interface

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

const
iphlpapilib = 'iphlpapi.dll';

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

  function SendArp(ipaddr:ulong; temp:dword; ulmacaddr:pointer;
  ulmacaddrleng:pointer) : DWord; StdCall;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function SendARP; external iphlpapilib name 'SendARP';

function GetMacAddr(const IPAddress: string): string;
var
lDestIP:ulong;
lMacAddr:array[0..5] of byte;
lPhyAddrLen:ulong;
begin
lDestIP:=inet_addr(PChar(IPAddress));
lPhyAddrLen:=length(lMacAddr);
SendARP(lDestIP,0,@lMacAddr,@lPhyAddrLen);
Result:=format('%2.2x-%2.2x-%2.2x-%2.2x-%2.2x-%2.2x',[lMacAddr[0],lMacAddr[1],lMacAddr[2],lMacAddr[3],lMacAddr[4],lMacAddr[5]]);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Edit2.Text := GetMacAddr(Edit1.Text);
end;

end.

Replies:

none

In response to:

www.cryer.info
Managed Newsgroup Archive