My Study/Delphi

해당 컴퓨터 MAC 어드레스 구해오기!

Kduks 2009. 1. 15. 12:30
반응형


자신의 컴퓨터 아이피로 MAC 어드레스 구해오는 소스입니다!


unit Unit1;

interface

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

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

  function SendARP(Destip,scrip:DWORD;pmacaddr:PDWORD;VAR phyAddrlen:DWORD):DWORD; stdcall ;external 'iphlpapi.dll';

var
  Form1: TForm1;

implementation

{$R *.dfm}

function GetMacFromIP(IP: String): String;
  type
    Tinfo = array[0..7] of byte;
var
  dwTargetIP: dword;
  dwMacAddress: array[0..1] of DWORD;
  dwMacLen: DWORD;
  dwResult: DWORD;
  X: Tinfo;
  stemp:string;
  iloop:integer;
begin
  dwTargetIP := Inet_Addr(pchar(ip));
  dwMacLen := 6;
  dwResult := SendARP(dwtargetip,0,@dwmacaddress[0], dwMaclen);
  if dwResult= NO_ERROR then
  begin
    x:= tinfo(dwMacAddress);

    for iloop:= 0 to 5 do
    begin
      stemp:= stemp+inttohex(x[iloop],2);
    end;

    Result:= stemp;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  // Edit1 에 도메인 내의 IP를 입력하고 버튼을 클릭하면 MAC 주소를 구해옵니다
  Edit2.Text := GetMacFromIP(Edit1.Text);
end;

end.



홧팅~!

-- 출처 : 김영대님의 Howto

반응형