delphi菜鸟,刚学delphi,要实现对校园网中的交换机和服务器网络连接情况检测
并检测交换机的cpu使用情况,不知道用什么方法实现,请教高手,在网络上看过很多用ping的例子,都不全,能否赐教,写的详细点!!
并检测交换机的cpu使用情况,不知道用什么方法实现,请教高手,在网络上看过很多用ping的例子,都不全,能否赐教,写的详细点!!
解决方案 »
- The Class function is called from a class constructor
- 怎么把在一个表中查询的数据放到另一个表中?
- 为什么我的应用服务器无法读取文件
- 窗体最小化后,发送哪个消息使其回复原状?——在线等待
- 郁闷啊(到一家公司就是上网),散分!
- 紧急求救!!
- ado初学:用参数从clientdataset取得的数据怎么不能applyupdates???
- 一个菜鸟级的问题,但要有VCL顶级的功夫,谁能应战。欢迎讨论!!!
- richedit1中如何读取第X个字符啊
- record类型怎么会有方法?
- 有参加CodeGear发布日的朋友进来谈谈自己感受啦~
- 三层架构中注册问题
unit ping;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, winsock, StdCtrls, ExtCtrls, ComCtrls, MMSystem;type
PIPOptionInformation = ^TIPOptionInformation;
TIPOptionInformation = packed record
TTL: Byte;
TOS: Byte;
Flags: Byte;
OptionsSize: Byte;
OptionsData: PChar;
end;
type PIcmpEchoReply = ^TIcmpEchoReply;
TIcmpEchoReply = packed record
Address: DWORD;
Status: DWORD;
RTT: DWORD;
DataSize:Word;
Reserved: Word;
Data: Pointer;
Options: TIPOptionInformation;
end;
TIcmpCreateFile = function: THandle; stdcall;
TIcmpCloseHandle = function(IcmpHandle: THandle): Boolean; stdcall;
TIcmpSendEcho = function(IcmpHandle:THandle;
DestinationAddress:DWORD;
RequestData: Pointer;
RequestSize: Word;
RequestOptions: PIPOptionInformation;
ReplyBuffer: Pointer;
ReplySize: DWord;
Timeout: DWord): DWord; stdcall;type
TForm1 = class(TForm)
Memo1: TMemo;
Panel1: TPanel;
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
HeaderControl1: THeaderControl;
CheckTimer: TTimer;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure CheckTimerTimer(Sender: TObject);
private
{ Private declarations }
hICMP: THANDLE;
IcmpCreateFile : TIcmpCreateFile;
IcmpCloseHandle:TIcmpCloseHandle;
IcmpSendEcho: TIcmpSendEcho;
ErrorCount:Integer;
public
{ Public declarations }
hICMPdll: HMODULE;
end;var
Form1: TForm1;
implementation{$R *.DFM}
{$R sound.RES}procedure PlayOne;
begin
PlaySound(PCHAR('ring'),Hinstance,SND_SYNC or SND_RESOURCE);
end;procedure TForm1.FormCreate(Sender: TObject);
begin
hICMPdll := LoadLibrary('icmp.dll');
@ICMPCreateFile:= GetProcAddress(hICMPdll, 'IcmpCreateFile');
@IcmpCloseHandle := GetProcAddress(hICMPdll, 'IcmpCloseHandle');
@IcmpSendEcho := GetProcAddress(hICMPdll, 'IcmpSendEcho');
hICMP := IcmpCreateFile;
//Memo1.Lines.Add(' ');
end;procedure TForm1.Button1Click(Sender: TObject);
var
IPOpt:TIPOptionInformation;
FIPAddress:DWORD;
pReqData,pRevData:PChar;
pIPE:PIcmpEchoReply;
FSize: DWORD;
MyString:string;
FTimeOut:DWORD;
BufferSize:DWORD;
begin
CheckTimer.Enabled:=False;
if Memo1.Lines.Count>500 then Memo1.Lines.Clear;
if Edit1.Text <> '' then
begin
FIPAddress:=inet_addr(PChar(Edit1.Text));
if Fipaddress=INADDR_NONE then
Memo1.Lines.Add('地址无效 Ping32 64')
else
begin
FSize:=80;
BufferSize:=SizeOf(TICMPEchoReply)+FSize;
GetMem(pRevData,FSize);
GetMem(pIPE,BufferSize);
FillChar(pIPE^, SizeOf(pIPE^), 0);
pIPE^.Data := pRevData;
MyString := 'Argen Ping32 Sending Message.';
pReqData := PChar(MyString);
FillChar(IPOpt, Sizeof(IPOpt), 0);
IPOpt.TTL:= 64;
FTimeOut :=4000;
IcmpSendEcho(hICMP, FIPAddress, pReqData, Length(MyString),@IPOpt, pIPE,
BufferSize, FTimeOut);
try
try
if pReqData^ = pIPE^.Options.OptionsData^ then
begin
ErrorCount:=0;
Memo1.Lines.Add(inttostr(Buffersize)+' '+
inttoStr(pIPE^.DataSize)+' '+IntToStr(pIPE^.RTT));
end;
except
Inc(ErrorCount,1);
if ErrorCount>=3 then
PlayOne;
Memo1.Lines.Add('系统检测到服务器出现异常!时间:'+DatetimeToStr(Now()));
end;
finally
FreeMem(pRevData);
FreeMem(pIPE);
end;
end;
end;
CheckTimer.Enabled:=True;
end;procedure TForm1.FormDestroy(Sender: TObject);
begin
icmpclosehandle(hicmp);
freelibrary(hicmpdll);
end;procedure TForm1.CheckTimerTimer(Sender: TObject);
begin
Button1.OnClick(self);
end;end.
至于交换机的CPU 得得看看交换机使用的操作系统是什么
属于网管系统