来自:c3411080, 时间:2003-12-29 13:49:00, ID:2381605
//可以获得在局域网里的IP以及internet中的IP
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,winsock,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
type
//copy the add_list
TAddrList = array [0..20] of PInAddr;
PAddrList = ^TAddrList;
var
phent : PHostEnt;
P: PAddrList;
I : Integer;
begin
{ CopyRight (C) Bowman 2000 }
{ MatthewBowman@21cn.com }
//detect yahoo.com
phent := GetHostByName(pchar(edit1.text));
if phent<>nil then
begin
I := 0;
P := PAddrList(phent^.h_Addr_list);
while P <> nil do
begin
listbox1.items.Add(StrPas(inet_ntoa(P^)));
Inc(I)
end
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
WSAData : TWSAData;
begin
//initiates use of WS2_32.DLL
if (WSAStartup(MAKEWORD(2,0),WSAData)<>0) then
raise Exception.Create('Winsock Version Error');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
WSACleanUP;
end;
end.