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)】
查看全文
相关阅读:
SDPA: Toward a Stateful Data Plane in Software-Defined Networking
带状态论文粗读(一)
P4: Programming Protocol-Independent Packet Processors
P4论文粗读笔记(一)
A Survey on the Security of Stateful SDN Data Planes
stateful openflow------整理openstate原理以及具体应用
Software-Defined Networking A Comprehensive Survey(一)
互联网安全(二)
互联网安全(一)
分层网络模型(三)
原文地址:https://www.cnblogs.com/xieyunc/p/9126662.html
最新文章
【转载】百度百科:FusionCube超融合
鲲鹏920的特性
ARM处理器、X86处理器和AI处理器的区别
块存储特性
SSD和HDD的区别
基于OceanStor Dorado V3存储之数据保护 Hyper 特性
基于OceanStor Dorado V3存储之精简高效 Smart 系列特性
在IT产品白皮书中遇到的缩略词
【转载】什么是NVMe?
SATA接口、PCI/PCIe、NVMe的介绍
热门文章
Android事件传递机制总结
JNI_day02
JNI_day01
Java对象实例化的过程
Android中数据缓存的处理
Android中Widget开发步骤
Android Studio在创建/导入项目的时候,一直处于building “XXX”gradle project info的解决办法
android中shape的使用介绍-2环形
看出每个应用程序最高可用内存是多少
根据现有Bitmap生成相同图案指定大小的新Bitmap
Copyright © 2011-2022 走看看