zoukankan
html css js c++ java
用Delphi实现Ping类
网络上的一个实现PING功能的类,修改了部分代码。
=======================================
unit ping; interface uses Windows, SysUtils, Classes, Controls, Winsock, StdCtrls; function pingip(ip:string):string; 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; Tping =class(Tobject) private { Private declarations } hICMP: THANDLE; IcmpCreateFile : TIcmpCreateFile; IcmpCloseHandle: TIcmpCloseHandle; IcmpSendEcho: TIcmpSendEcho; public procedure pinghost(ip:string;var info:string); constructor create; destructor destroy;override; { Public declarations } end; var hICMPdll: HMODULE; implementation constructor Tping.create; begin inherited create; hICMPdll := LoadLibrary('icmp.dll'); @ICMPCreateFile := GetProcAddress(hICMPdll, 'IcmpCreateFile'); @IcmpCloseHandle := GetProcAddress(hICMPdll,'IcmpCloseHandle'); @IcmpSendEcho := GetProcAddress(hICMPdll, 'IcmpSendEcho'); hICMP := IcmpCreateFile; end; destructor Tping.destroy; begin FreeLibrary(hIcmpDll); inherited destroy; end; procedure Tping.pinghost(ip:string;var info:string); var // IP Options for packet to send IPOpt:TIPOptionInformation; FIPAddress:DWORD; pReqData,pRevData:PChar; // ICMP Echo reply buffer pIPE:PIcmpEchoReply; FSize: DWORD; MyString:string; FTimeOut:DWORD; BufferSize:DWORD; begin if ip<>'' then begin FIPAddress := inet_addr(PChar(ip)); FSize := 40; BufferSize := SizeOf(TICMPEchoReply) + FSize; GetMem(pRevData,FSize); GetMem(pIPE,BufferSize); FillChar(pIPE^, SizeOf(pIPE^), 0); pIPE^.Data := pRevData; MyString := 'Test Net - Sos Admin'; pReqData := PChar(MyString); FillChar(IPOpt, Sizeof(IPOpt), 0); IPOpt.TTL := 64; FTimeOut := 4000; try IcmpSendEcho(hICMP, FIPAddress, pReqData, Length(MyString),@IPOpt, pIPE, BufferSize, FTimeOut); if pReqData^ = pIPE^.Options.OptionsData^ then info:=ip+ ' ' + IntToStr(pIPE^.DataSize) + ' ' +IntToStr(pIPE^.RTT); except info:='Can not find host!'; FreeMem(pRevData); FreeMem(pIPE); Exit; end; FreeMem(pRevData); FreeMem(pIPE); end; end; function pingip(ip:string):string; var str:string; ping:Tping; begin ping:=Tping.create ;//一定要初试化哦 ping.pinghost('127.0.0.1',str); result:=str; ping.destroy ; end; end.
谢祥选【小宇飞刀(xieyunc)】
查看全文
相关阅读:
Atitit.兼具兼容性和扩展性的配置方案attilax总结
Atitit.异步编程技术原理与实践attilax总结
Atitit.异步编程技术原理与实践attilax总结
Atitit. 获取cpu占有率的 java c# .net php node.js的实现
Atitit. 获取cpu占有率的 java c# .net php node.js的实现
Atitit.研发团队的管理原则---立长不立贤与按资排辈原则
Atitit.研发团队的管理原则---立长不立贤与按资排辈原则
Atitit.研发团队与公司绩效管理的原理概论的attilax总结
Atitit.研发团队与公司绩效管理的原理概论的attilax总结
Atitit selenium3 新特性
原文地址:https://www.cnblogs.com/xieyunc/p/2793657.html
最新文章
小程序开通微信支付 --- 微信商户平台绑定微信小程序APPID
宝塔面板快速开启https服务
angular --- http服务
jquery实现ajax跨域请求!亲测有效
码云上怎么删除项目?解决办法
ssh-keygen 不是内部或外部命令解决办法!
git下载和上传项目
Atitit 三论”(系统论、控制论、信息论
Atitit 三论”(系统论、控制论、信息论
Atitit.识别损坏的图像
热门文章
Atitit.信息论原理概论attilax总结
Atitit.识别损坏的图像
Atitit.信息论原理概论attilax总结
Atitit.log日志技术的最佳实践attilax总结
Atitit.log日志技术的最佳实践attilax总结
Atitit 《控制论原理与概论attilax总结
Atitit 《控制论原理与概论attilax总结
Atitit.日志系统slf4j的使用
Atitit.日志系统slf4j的使用
Atitit.兼具兼容性和扩展性的配置方案attilax总结
Copyright © 2011-2022 走看看