• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Delphi的ping源程序

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

unit ping;

 

interface

 

uses

  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,

Dialogs,winsock,

  StdCtrls, Grids;

type

PIPOptionInformation=^TIPOptionInformation;

TIPOptionInformation = packed record

TTL: Byte;

TOS: Byte;

Flags: Byte;

OptionsSize: Byte;

OptionsData: PChar;

end;

type 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;RequestDa

ta: Pointer;RequestSize: Word;RequestOptions: PIPOptionInformation;ReplyBuffer

: Pointer;ReplySize: DWord;Timeout: DWord): DWord; stdcall;

type

Tfrmping = class(TForm)

    echogrid: TStringGrid;

    ipaddr: TEdit;

    Label1: TLabel;

    ping: TButton;

procedure FormCreate(Sender: TObject);

    procedure pingClick(Sender: TObject);

    procedure FormDestroy(Sender: TObject);

private

hICMP: THANDLE;

IcmpCreateFile : TIcmpCreateFile;

IcmpCloseHandle:TIcmpCloseHandle;

IcmpSendEcho: TIcmpSendEcho;

line:integer;

{ Private declarations }

public

hICMPdll: HMODULE;{ Public declarations }

end;

 

var

  frmping: Tfrmping;

 

implementation

 

{$R *.DFM}

 

procedure Tfrmping.FormCreate(Sender: TObject);

begin

hICMPdll := LoadLibrary('icmp.dll');

@ICMPCreateFile:= GetProcAddress(hICMPdll, 'IcmpCreateFile');

@IcmpCloseHandle := GetProcAddress(hICMPdll, 'IcmpCloseHandle');

@IcmpSendEcho := GetProcAddress(hICMPdll, 'IcmpSendEcho');

hICMP := IcmpCreateFile;

echogrid.Cells[0,0]:='返回地址';

echogrid.cells[1,0]:='返回数据包大小';

echogrid.Cells[2,0]:='状态';

echogrid.Cells[3,0]:='RTT(Round-Trip-Time)';

line:=1;

end;

 

procedure Tfrmping.pingClick(Sender: TObject);

var

IPOpt:TIPOptionInformation;// IP Options for packet to send

FIPAddress:DWORD;

pReqData,pRevData:PChar;

pIPE:PIcmpEchoReply;// ICMP Echo reply buffer

FSize: DWORD;

MyString:string;

FTimeOut:DWORD;

BufferSize:DWORD;

begin

if iPaddr.Text <> '' then

begin

FIPAddress:=inet_addr(PChar(ipaddr.Text));

if Fipaddress=INADDR_NONE then Messagebox(self.handle,'地址无效

','Ping32',64)

else

begin

FSize:=40;

BufferSize:=SizeOf(TICMPEchoReply)+FSize;

GetMem(pRevData,FSize);

GetMem(pIPE,BufferSize);

FillChar(pIPE^, SizeOf(pIPE^), 0);

pIPE^.Data := pRevData;

MyString := 'Argen Ping32 Sending Message.';

pReqData := PChar(MyString);

FillChar(IPOpt, Sizeof(IPOpt), 0);

IPOpt.TTL:= 64;

FTimeOut :=10000;

IcmpSendEcho(hICMP, FIPAddress, pReqData, Length(MyString),@IPOpt, pIPE,

BufferSize, FTimeOut);

try

try

if pReqData^ = pIPE^.Options.OptionsData^ then

with echogrid do

begin

if line>1 then rowcount:=line+1;

cells[0,line]:=ipaddr.Text;

cells[1,line]:=inttoStr(pIPE^.DataSize);

cells[3,line]:=IntToStr(pIPE^.RTT);

row:=rowcount-1;

line:=line+1;

end;

except

Messagebox(self.handle,'目标不可到','Ping32',64)

end;

finally

FreeMem(pRevData);

FreeMem(pIPE);

end;

end;

end;

end;

procedure Tfrmping.FormDestroy(Sender: TObject);

begin

icmpclosehandle(hicmp);

freelibrary(hicmpdll);

end;

 

end.


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
四大机器学习编程语言对比:R、Python、MATLAB、Octave发布时间:2022-07-18
下一篇:
SQLDirect6.5Source(Delphi5-10.1Berlin)发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap