Mengecek Nama Host


Tips & Trik Delphi, Tips Belajar Delphi, Belajar Delphi Online
unit Unit1;

interface

uses

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

type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Edit1: TEdit;

procedure Button1Click(Sender: TObject);
private
function IPAddrToName(IPAddr: String): String;
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses winsock;

{$R *.dfm}

function TForm1.IPAddrToName(IPAddr: string): string;
var
SockAddrIn: TSockAddrIn;
HostEnt: PHostEnt;
WSAData: TWSAData;
begin
WSAStartup($101, WSAData);
try
SockAddrIn.sin_addr.s_addr := inet_addr(PChar(IPAddr));
HostEnt := GetHostByAddr(@SockAddrIn.sin_addr.S_addr, 4, AF_INET);
if Assigned(HostEnt) then
Result := StrPas(Hostent^.h_name)
else
Result := ”;
finally
WSACleanup;
end;
end;

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

end.

TransCODE Software

Tinggalkan Balasan

Please log in using one of these methods to post your comment:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s