유돌이

calendar

1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30

Notice

2019. 10. 4. 09:39 델파이

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Edit2: 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.

posted by 유돌이