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)】
查看全文
相关阅读:
java_IO流之 NIO
No enclosing instance of type Outer is accessible. Must qualify the allocation with an enclosing instance of type Outer (e.g. x.new A() where x is an instance of Outer)
JAVA I/O流 之入门
10年老司机经验总结--程序员兼职的那些事
python 去除html 超链接href 如何实现?
《模式分类(原书第二版)》pdf格式下载电子书免费下载
通知-招财猫问题通知专用
Centos6.5 安装 python3.5 虚拟环境 virtualenvwrapper
5.区块链平台以太坊从入门到精通之 以太网区块链网络
4.区块链平台以太坊从入门到精通之 以太币
原文地址:https://www.cnblogs.com/xieyunc/p/2793657.html
最新文章
An incompatible version [1.1.29] of the APR based Apache Tomcat Native library is installed, while Tomcat requires version [1.2.14]
Eclipse:An error has occurred. See error log for more details. java.lang.NullPointerException
启动Eclipse发生错误:An internal error occurred during: "Initializing Java Tooling".
idea中用maven打包spring的java项目(非web)
Java并发编程:线程池的使用(转载)
奇葩问题:同样的字符串equal为false
java线程安全总结
java线程安全总结
java线程安全(单例模式)(转载)
zookeeper: web ui工具的安装
热门文章
Storm: 集群安装和配置
Nginx 高级配置
redis 服务相关
git 删除错误提交的commit
从设计模式说起JAVA I/O流
蘑菇街技术笔试编程题
360技术笔试编程题
新浪微博笔试题
Jconsole: JAVA 监视和管理控制台简介
360WIFI下使用Fiddler抓取手机APP流量
Copyright © 2011-2022 走看看