谁有Ping的Delphi源程序?给我一份. 谁有Ping的Delphi源程序?给我一份. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 {用 Delphi实现ping的例子[email protected]}unit PingUnit;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls,winsock;typePIPOptionInformation = ^TIPOptionInformation;TIPOptionInformation = packed recordTTL: Byte;TOS: Byte;Flags: Byte;OptionsSize: Byte;OptionsData: PChar;end;PIcmpEchoReply = ^TIcmpEchoReply;TIcmpEchoReply = packed recordAddress: DWORD;Status: DWORD;RTT: DWORD;DataSize: Word;Reserved: Word;Data: Pointer;Options: TIPOptionInformation;phe: pHostent; 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; TPingForm = class(TForm) StatusShow: TMemo; Panel1: TPanel; pingedit: TEdit; exebutton: TButton; Label1: TLabel; procedure FormCreate(Sender: TObject); procedure exebuttonClick(Sender: TObject); private { Private declarations } hICMP: THANDLE; IcmpCreateFile : TIcmpCreateFile; IcmpCloseHandle: TIcmpCloseHandle; IcmpSendEcho: TIcmpSendEcho; public { Public declarations } end;var PingForm: TPingForm; HostName:string;implementation{$R *.DFM}procedure TPingForm.FormCreate(Sender: TObject); var WSAData: TWSAData; hICMPdll: HMODULE; begin wsastartup($101,wsadata); hICMPdll := LoadLibrary('icmp.dll'); @ICMPCreateFile := GetProcAddress(hICMPdll, 'IcmpCreateFile'); @IcmpCloseHandle := GetProcAddress(hICMPdll, 'IcmpCloseHandle'); @IcmpSendEcho := GetProcAddress(hICMPdll, 'IcmpSendEcho'); hICMP := IcmpCreateFile; StatusShow.Text := ''; statusshow.Align := alclient; StatusShow.Lines.Add('目的IP地址 字节数 返回时间(毫秒)'); end;procedure TPingForm.exebuttonClick(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 if pReqData^ = pIPE^.Options.OptionsData^ then begin StatusShow.Lines.Add(PChar(PingEdit.Text) + ' ' +IntToStr(pIPE^.DataSize) + ' ' +IntToStr(pIPE^.RTT)); end; except messagedlg('没有找到该IP地址!',mtinformation,[mbok],0); end; pIPE^.Phe := GetHostByAddr(@FIPAddress, 4, AF_INET); if pIPE^.Phe <> Nil then HostName:=pIPE^.Phe^.h_name; caption:=hostname; FreeMem(pRevData); FreeMem(pIPE); end; end;end. VB的On Error Resume Next在DELPHI中应怎么写? 高手帮忙!! TQuery数据库连接中默认路径的问题,求解 FastReport 的几个小问题 IntraWeb总是把我弄很奇怪:简单问题,大家只要用过都进来坐坐吧! 查询时出错,是什么原因? delphi波特率设置 急!!!请问shellexecute用的是那个头文件?在线等待,立即给分! 清空 求助?谁能帮我,改变DELPHI编译产生的可制行文件最终图标,即不是默认的那个,怎样在代码中改变呢? findcsdn再请来接分,感谢两天来的帮助,问题已经成功解决,不胜感激 各位大哥,小弟求救.........
用 Delphi实现ping的例子
[email protected]
}
unit PingUnit;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, 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;
phe: pHostent;
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;
TPingForm = class(TForm)
StatusShow: TMemo;
Panel1: TPanel;
pingedit: TEdit;
exebutton: TButton;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure exebuttonClick(Sender: TObject);
private
{ Private declarations } hICMP: THANDLE;
IcmpCreateFile : TIcmpCreateFile;
IcmpCloseHandle: TIcmpCloseHandle;
IcmpSendEcho: TIcmpSendEcho;
public
{ Public declarations }
end;var
PingForm: TPingForm; HostName:string;implementation{$R *.DFM}procedure TPingForm.FormCreate(Sender: TObject);
var
WSAData: TWSAData;
hICMPdll: HMODULE;
begin
wsastartup($101,wsadata);
hICMPdll := LoadLibrary('icmp.dll');
@ICMPCreateFile := GetProcAddress(hICMPdll, 'IcmpCreateFile');
@IcmpCloseHandle := GetProcAddress(hICMPdll, 'IcmpCloseHandle');
@IcmpSendEcho := GetProcAddress(hICMPdll, 'IcmpSendEcho');
hICMP := IcmpCreateFile;
StatusShow.Text := '';
statusshow.Align := alclient;
StatusShow.Lines.Add('目的IP地址 字节数 返回时间(毫秒)');
end;
procedure TPingForm.exebuttonClick(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
if pReqData^ = pIPE^.Options.OptionsData^ then
begin
StatusShow.Lines.Add(PChar(PingEdit.Text) + ' ' +IntToStr(pIPE^.DataSize) + ' ' +IntToStr(pIPE^.RTT));
end;
except
messagedlg('没有找到该IP地址!',mtinformation,[mbok],0);
end;
pIPE^.Phe := GetHostByAddr(@FIPAddress, 4, AF_INET);
if pIPE^.Phe <> Nil then HostName:=pIPE^.Phe^.h_name;
caption:=hostname;
FreeMem(pRevData);
FreeMem(pIPE);
end;
end;end.