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: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, winsock;
type TForm1 = class(TForm) RichEdit1: TRichEdit; Button1: TButton; Edit1: TEdit; procedure Button1Click(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject); var addr : TInaddr; var hostEntry : pHostEnt; wsdata : TWSAData; fLasterr : integer; fHandle : THandle; winsockOK : boolean; begin richedit1.Lines.Clear; fLasterr := WSAStartup(makeWord(1,1), wsdata); case fLasterr of WSAEINVAL, WSASYSNOTREADY, WSAVERNOTSUPPORTED : winsockOK := false; else winsockOK := true; end; if winsockOK then begin fhandle := AllocateHWnd(WndProc); richedit1.Lines.Add('Ready...'); end; getmem(hostEntry, MAXGETHOSTSTRUCT); richedit1.lines.add('--------------------------------------'); hostentry := getHostbyName(pchar(edit1.text)); if hostentry <> nil then begin richedit1.Lines.Add('looking up for Host : ' + hostentry.h_name); addr := PInaddr( hostentry^.h_addr_list^)^; richedit1.lines.add('IP : ' + inet_ntoa(addr)); end else begin richedit1.Lines.Add('lookup failed for '+edit1.text); end; end;
end. |