软件调用windows下的tracert仅能看到ping多少,我现在想得到丢包率多少应如何处理呢?

解决方案 »

  1.   

    自己去ICMP套节子去实现tracert操作,也不是很困难,这样可以很好的控制
      

  2.   

    就是对原始套接字编程,用socket API,如果想简单,就用Indy的控件
      

  3.   


    unit Unit1;interfaceusesWindows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Winsock,StdCtrls;typePIPOptionInformation = ^TIPOptionInformation;TIPOptionInformation = packed recordTTL: Byte;TOS: Byte;Flags: Byte;OptionsSize: Byte;OptionsData: PChar;end;PIcmpEchoReply = ^TIcmpEchoReply;TIcmpEchoReply = packed recordAddress: 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;TForm1 = class(TForm)Memo1: TMemo;Button1: TButton;PingEdit: TEdit;procedure FormCreate(Sender: TObject);procedure Button1Click(Sender: TObject);private{ Private declarations }hICMP: THANDLE;IcmpCreateFile : TIcmpCreateFile;IcmpCloseHandle: TIcmpCloseHandle;IcmpSendEcho: TIcmpSendEcho;public{ Public declarations }end;varForm1: TForm1;implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);varhICMPdll: HMODULE;beginhICMPdll := LoadLibrary('icmp.dll');@ICMPCreateFile := GetProcAddress(hICMPdll, 'IcmpCreateFile');@IcmpCloseHandle := GetProcAddress(hICMPdll,'IcmpCloseHandle');@IcmpSendEcho := GetProcAddress(hICMPdll, 'IcmpSendEcho');hICMP := IcmpCreateFile;Memo1.Text := '';Memo1.Lines.Add('目的IP地址 字节数 返回时间(毫秒)');end;procedure TForm1.Button1Click(Sender: TObject);varIPOpt:TIPOptionInformation;// IP Options for packet to sendFIPAddress:DWORD;pReqData,pRevData:PChar;pIPE:PIcmpEchoReply;// ICMP Echo reply bufferFSize: DWORD;MyString:string;FTimeOut:DWORD;BufferSize:DWORD;beginif PingEdit.Text <> '' thenbeginFIPAddress := inet_addr(PChar(PingEdit.Text));FSize := 40;BufferSize := SizeOf(TICMPEchoReply) + FSize;GetMem(pRevData,FSize);GetMem(pIPE,BufferSize);FillChar(pIPE^, SizeOf(pIPE^), 0);pIPE^.Data := pRevData;MyString := 'Hello,World';pReqData := PChar(MyString);FillChar(IPOpt, Sizeof(IPOpt), 0);IPOpt.TTL := 64;FTimeOut := 4000;tryIcmpSendEcho(hICMP, FIPAddress, pReqData, Length(MyString),@IPOpt, pIPE, BufferSize, FTimeOut);if pReqData^ = pIPE^.Options.OptionsData^ thenMemo1.Lines.Add(PChar(PingEdit.Text) + ' ' + IntToStr(pIPE^.DataSize) + ' ' +IntToStr(pIPE^.RTT));exceptMemo1.Lines.Add('Cant resolve host!');FreeMem(pRevData);FreeMem(pIPE);Exit;end;FreeMem(pRevData);FreeMem(pIPE);end;end;end.