列出本机所有的Ip

2008-04-09 04:23:03来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

unit Unit1;

interface

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

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

var
Form1: TForm1;

implementation

{$R *.dfm}

type
TaPInAddr = Array[0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;


procedure TForm1.Button1Click(Sender: TObject);
var
phe: PHostEnt;
pptr: PaPInAddr;
Buffer: Array[0..63] of Char;
I: Integer;
GInitData: TWSAData;
st:TstringList;
begin
WSAStartup($101, GInitData);
st:=TStringList.Create;
GetHostName(Buffer, SizeOf(Buffer));
phe := GetHostByName(buffer);
if phe = nil then
begin
Exit;
end;
pPtr := PaPInAddr(phe^.h_addr_list);
I := 0;
while pPtr^[I] <> nil do
begin
st.Add(inet_ntoa(pptr^[I]^));
showmessage(st.strings[i]);
Inc(I);

end;
WSACleanup;
end;

end.

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:Delphi程序设计规范

下一篇:怎样在C#中调用Delphi6写的DLL