runxinzhi.com
首页
百度搜索
用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)】
相关阅读:
python笔记之re模块学习
python笔记之面向对象
C# 静态类和非静态类(实例类)
占位符的使用
数据类型和数据类型转换
win7 安装 memcached
php 汉字转换成拼音
apache window环境下本地配置虚拟主机
在浏览器输入一个网址到得到页面的过程
浅谈线程池ThreadPoolExecutor核心参数
原文地址:https://www.cnblogs.com/xieyunc/p/9126662.html
最新文章
按键技巧
Oracle的nvl()和substr()方法
Mahout简介
Hive简介
Nutch1.2 的安装与使用
nutch从搜索引擎到网络爬虫
hadoop一代集群运行代码案例
Hadoop-1.2.1伪分布下 hive-0.10.0内嵌模式安装
数据挖掘简介
nutch相关目录说明
热门文章
马士兵 spring 视频笔记
马士兵hibernate(原始笔记)
数据驱动
python-selenium笔记之元素定位
接口自动化测试之基本认证处理
http协议
window下安装Apache Tomcat
Postman工具初识
python笔记之socket
python笔记之进程线程
Copyright © 2020-2023
润新知