S sungw Unregistered / Unconfirmed GUEST, unregistred user! 2000-08-14 #1 如何用delphi去 ping 一个ip地址? 原将50分送给第一个回答这个问题的朋友.
X xujiancai Unregistered / Unconfirmed GUEST, unregistred user! 2000-08-14 #2 你可以用shellexecute调用ping这条命令。
W wjiachun Unregistered / Unconfirmed GUEST, unregistred user! 2000-08-14 #9 http://www.gislab.ecnu.edu.cn/delphibbs/DispQ.asp?LID=262373 有,太长了,你自己去看吧
Z zengr Unregistered / Unconfirmed GUEST, unregistred user! 2000-08-14 #10 {PING是利用TCP/IP协议包中的ICMP协议的功能。所以可以利用WINDOWS的SYSTEM目录下的 icmp.dll所提供的功能来完成。PING的操作通过对该DLL的调用。其中 IcmpCreateFile:打开一个句柄,通过该句柄可以发送ICMP的请求回送报文 IcmpCloseHandle:关闭有上面函数打开的句柄 IcmpSendEcho:通过打开的句柄发送ICMP请求,在超时或应答报文接收后返回。 记住:一定要包含winsock单元!} 下面为一个小程序 unit ping_demo; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,winsock, StdCtrls, ExtCtrls; type PIPOptionInformation=^TIPOptionInformation; TIPOptionInformation = packed record TTL:Byte; TOS:Byte; Flags:Byte; OptionsSize :Byte; OptionsDataChar; end; PicmpEchoReply=^TicmpEchoReply; TicmpEchoReply=packed record AddressWORD; StatusWORD; RTTWORD; DataSize:Word; Reserved:Word; Dataointer; Options:TIPOptionInformation; end; TicmpCreateFile=function:THandle;stdcall; TicmpCloseHandle=function(IcmpHandle:Thandle):Boolean;stdcall; TicmpSendEcho=function( IcmpHandle:Thandle; DestinationAddressWORD; RequestDataointer; RequestSize:Word; RequestOptionsIPOptionInformation; ReplyBufferointer; ReplySizeWORD; TimeoutWORD )Word;stdcall; TForm1 = class(TForm) Panel1: TPanel; Button1: TButton; Edit1: TEdit; Label1: TLabel; Memo1: TMemo; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } hICMP:THANDLE; IcmpCreateFile:TicmpCreateFile; IcmpCloseHandle:TicmpCloseHandle; IcmpSendEcho:TicmpSendEcho; public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.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; //程序开始时对Winsocket进行初始化 end; procedure TForm1.Button1Click(Sender: TObject); var IPOpt:TIPOptionInformation; FIPAddressWORD; pReQData,pRevDataChar; pIPEicmpEchoReply; FsizeWORD; MyString:String; FtimeoutWORD; BufferSizeWORD; begin if Edit1.Text <>'' then begin FIPAddress := inet_addr(PChar(Edit1.Text)); Fsize := 40; BufferSize := SizeOf(TICMPEchoReply)+Fsize; GetMem(pRevData,fSize); GetMem(pIPE,BufferSize); fillChar(pIPE^,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 Memo1.Lines.Add(PChar(Edit1.Text)+' '+IntToStr(pIPE^.DataSize)+' '+IntToStr(pIPE^.RTT)); except MessageDlg('No Dest IP',mtinformation,[mbok],0); end; FreeMem(pRevData); FreeMem(pIPE); end; end; end.
{PING是利用TCP/IP协议包中的ICMP协议的功能。所以可以利用WINDOWS的SYSTEM目录下的 icmp.dll所提供的功能来完成。PING的操作通过对该DLL的调用。其中 IcmpCreateFile:打开一个句柄,通过该句柄可以发送ICMP的请求回送报文 IcmpCloseHandle:关闭有上面函数打开的句柄 IcmpSendEcho:通过打开的句柄发送ICMP请求,在超时或应答报文接收后返回。 记住:一定要包含winsock单元!} 下面为一个小程序 unit ping_demo; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,winsock, StdCtrls, ExtCtrls; type PIPOptionInformation=^TIPOptionInformation; TIPOptionInformation = packed record TTL:Byte; TOS:Byte; Flags:Byte; OptionsSize :Byte; OptionsDataChar; end; PicmpEchoReply=^TicmpEchoReply; TicmpEchoReply=packed record AddressWORD; StatusWORD; RTTWORD; DataSize:Word; Reserved:Word; Dataointer; Options:TIPOptionInformation; end; TicmpCreateFile=function:THandle;stdcall; TicmpCloseHandle=function(IcmpHandle:Thandle):Boolean;stdcall; TicmpSendEcho=function( IcmpHandle:Thandle; DestinationAddressWORD; RequestDataointer; RequestSize:Word; RequestOptionsIPOptionInformation; ReplyBufferointer; ReplySizeWORD; TimeoutWORD )Word;stdcall; TForm1 = class(TForm) Panel1: TPanel; Button1: TButton; Edit1: TEdit; Label1: TLabel; Memo1: TMemo; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } hICMP:THANDLE; IcmpCreateFile:TicmpCreateFile; IcmpCloseHandle:TicmpCloseHandle; IcmpSendEcho:TicmpSendEcho; public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.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; //程序开始时对Winsocket进行初始化 end; procedure TForm1.Button1Click(Sender: TObject); var IPOpt:TIPOptionInformation; FIPAddressWORD; pReQData,pRevDataChar; pIPEicmpEchoReply; FsizeWORD; MyString:String; FtimeoutWORD; BufferSizeWORD; begin if Edit1.Text <>'' then begin FIPAddress := inet_addr(PChar(Edit1.Text)); Fsize := 40; BufferSize := SizeOf(TICMPEchoReply)+Fsize; GetMem(pRevData,fSize); GetMem(pIPE,BufferSize); fillChar(pIPE^,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 Memo1.Lines.Add(PChar(Edit1.Text)+' '+IntToStr(pIPE^.DataSize)+' '+IntToStr(pIPE^.RTT)); except MessageDlg('No Dest IP',mtinformation,[mbok],0); end; FreeMem(pRevData); FreeMem(pIPE); end; end; end.
A atman Unregistered / Unconfirmed GUEST, unregistred user! 2000-08-16 #12 zengr! 这段程序最终不能返回其他的状态! 如 Time Out ..... !
S sungw Unregistered / Unconfirmed GUEST, unregistred user! 2000-08-17 #14 我测试了zengr提供的程序,发现不能工作. 原理是对的,我谢谢zengr! 还有honestman,你的提醒,我已经下载了ICS,通过和zengr提供的代码比较, 发现问题之一是处在:代码没有处理本机进程和跨机进程的区别对待上.....
我测试了zengr提供的程序,发现不能工作. 原理是对的,我谢谢zengr! 还有honestman,你的提醒,我已经下载了ICS,通过和zengr提供的代码比较, 发现问题之一是处在:代码没有处理本机进程和跨机进程的区别对待上.....
D delphisnail Unregistered / Unconfirmed GUEST, unregistred user! 2000-08-17 #15 IGMP的控件很多,ics,indy都有的