WEB开发网
开发学院软件开发Delphi 列出本机所有的Ip 阅读

列出本机所有的Ip

 2006-02-04 13:55:05 来源:WEB开发网   
核心提示: unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,winsock;type TForm1 = class(TForm) Bu
 

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.

Tags:列出 本机 所有

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接