Delphi获得计算机系统配置,"获得主机名和IP地址" 和 "监测局域网内计算机"...

"获得主机名和IP地址" 和 "监测局域网内计算机" Delphi / Windows SDK/API

http://www.delphi2007.net/DelphiBase/html/delphi_20061209192223212.html

哪位大虾可以帮帮忙啊,帮我把这两段程序分析一下啊,万分感激!!!!!!

获得主机名和IP地址:

hostName;

interface

uses

Windows,   Messages,   SysUtils,   Classes,   Graphics,   Controls,   Forms,Dialogs,

StdCtrls,   Winsock;

type

TForm1   =   class(TForm)

Edit1:   TEdit;Label1:   TLabel;Label2:   TLabel;Edit2:   TEdit;Edit3:   TEdit;

Label3:   TLabel;Button1:   TButton;

procedure   Button1Click(Sender:   TObject);

private

{   Private   declarations   }

public

{   Public   declarations   }

end;

var

Form1:   TForm1;

implementation

{$R   *.DFM}

procedure   TForm1.Button1Click(Sender:   TObject);

var

Ip:string;

Ipstr:string;

Buffer:Array[1..32]   of   char;

i:integer;

WSData:TWSAdata;

Host:PHostEnt;

begin

if   WSAstartup(2,WSData)<>0   then

begin

ShowMessage('WS2_32.DLL初始化失败!');  halt;   end;

try

if   GetHostName(@Buffer[1],32)<>0   then

begin

ShowMessage('没有得到主机名!');      halt;  end;

except

ShowMessage('没有成功返回主机名');      halt;   end;

Host   :=   GetHostByName(@Buffer[1]);

if   Host   =   nil   then

begin

ShowMessage('IP地址为空');        halt;   end

else

begin

Edit2.Text   :=   Host.h_name;

Edit3.Text   :=   Chr(Host.h_addrtype+64);

for   i:=1   to   4   do

begin

Ip:=IntToStr(Ord(Host.h_addr^[i-1]));

ShowMessage('分段IP地址为:'+Ip);

if   i<4   then

Ipstr   :=   Ipstr   +   Ip   +   '.'

else

Edit1.Text:=Ipstr+Ip;   end;    end;

WSACleanup;     end;         end.

监测局域网内计算机:

unit   local;

interface

uses

Windows,   Messages,   SysUtils,   Classes,   Graphics,   Controls,   Forms,   Dialogs,

StdCtrls,Winsock;

type

TForm1   =   class(TForm)

Button1:   TButton;       Edit1:   TEdit;       Memo1:   TMemo;     Label1:   TLabel;

procedure   Button1Click(Sender:   TObject);

private

{   Private   declarations   }

public

{   Public   declarations   }

end;

var

Form1:   TForm1;

function   FindComputer(ComputerName:   string):Boolean;

implementation

{$R   *.DFM}

function   FindComputer(ComputerName:   string):Boolean;

var

WSAData:   TWSAData;

HostEnt:   PHostEnt;

begin

Result   :=True;

WSAStartup(2,   WSAData);

HostEnt   :=   gethostbyname(PChar(ComputerName));

if   HostEnt   =   nil   then   Result   :=   False;

WSACleanup;           end;

procedure   TForm1.Button1Click(Sender:   TObject);

begin

if   FindComputer(edit1.text)=True   then

Memo1.lines.Add(edit1.text+'在局域网上!')

else

Memo1.lines.Add(edit1.text+'不在局域网上!');       end;       end.

posted on 2009-02-11 16:49 delphi2007 阅读(271) 评论(0)  编辑 收藏 引用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值