使用ICMP协议,自己写一个类似Ping的函数,通过判断返回值来确定那个服务器比较快!
解决方案 »
- 再求treeview使用过程.
- DBcombobox录入问题?
- ExpressQuantumGrid多选的时候,如何得到多选的这些数据的ID,急!谢谢
- 出售DELPHI原代码
- 在DELPHI中用建表时出错,程序会出中止.什么办法可以避免程序中止??
- WM_CTLCOLOREDIT消息如何使用?(急,在线等待)
- 资源文件是什麽,怎麽使用?
- dephi制作的程序在不同分辨率下运行(急用)
- 刚才的TAPI,现在继续给分,求示例源代码,越全面越好,50分,没法多给了
- 如何动态修改ActionList的OnExecute事件?
- 中国软件业的程序员认为比较黑的公司清单(另开:只为长春用户)
- 问个小问题,关于Tblobfield
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,winsock;type
PIPOptionInformation = ^TIPOptionInformation;
TIPOptionInformation=packed record
TTL: Byte;
TOS: Byte;
Flags: Byte;
OptionsSize: Byte;
OptionsData: PChar;
end;
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;
TTMyPing = class(TForm)
PingEdit: TEdit;
Label1: TLabel;
StatusShow: TMemo;
exebtn: TButton;
procedure exebtnClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
hICMP: THANDLE;
IcmpCreateFile : TIcmpCreateFile;
IcmpCloseHandle:TIcmpCloseHandle;
IcmpSendEcho: TIcmpSendEcho;
public
WSAData:TWSAData;
{ Public declarations }
end;var
TMyPing: TTMyPing;implementation{$R *.DFM}procedure TTMyPing.exebtnClick(Sender: TObject);
var
IPOpt:TIPOptionInformation;// IP Options for packet to send
FIPAddress:DWORD;
pReqData,pRevData:PChar;
pIPE:PIcmpEchoReply;// ICMP Echo reply buffer
FSize: DWORD;
MyString:string;
FTimeOut:DWORD;
BufferSize:DWORD;
begin
if PingEdit.Text <> '' then
begin
FIPAddress:=inet_addr(pchar(Pingedit.text));
FSize := 40;
BufferSize := SizeOf(TICMPEchoReply) + FSize;
GetMem(pRevData,FSize);
GetMem(pIPE,BufferSize);
FillChar(pIPE^, SizeOf(pIPE^), 0);
pIPE^.Data := pRevData;
MyString := '-------Hello,World!---------------';
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
StatusShow.Lines.Add(PChar(PingEdit.Text) + '-----'
+IntToStr(pIPE^.DataSize) + '-----' +IntToStr(pIPE^.RTT));
end;
except
showmessage('没有找到Ip地址!');
end;
finally
FreeMem(pRevData);
FreeMem(pIPE);
end;
end
else
showmessage('请输入Ip地址');
end;
// 通过上面的编程,我们就实现了Ping功能的界面操作。实际上,ICMP协议的功能还
//有很多,都可以通过对Icmp.dll的函数调用来实现。
procedure TTMyPing.FormCreate(Sender: TObject);
var
hICMPdll: HMODULE;
begin // Load the icmp.dll stuff
WSAStartup(2,WSAData);
hICMPdll := LoadLibrary('icmp.dll');
@ICMPCreateFile := GetProcAddress(hICMPdll, 'IcmpCreateFile');
@IcmpCloseHandle := GetProcAddress(hICMPdll, 'IcmpCloseHandle');
@IcmpSendEcho := GetProcAddress(hICMPdll, 'IcmpSendEcho');
hICMP :=IcmpCreateFile;
StatusShow.Text := '';
StatusShow.Lines.Add('目的IP地址-----字节数----返回时间(毫秒)');
end;procedure TTMyPing.FormClose(Sender: TObject; var Action: TCloseAction);
begin
WSACleanup();
end;end.
能不能把你的程序帮我写点注释,尤其是定义类型处,谢谢。