看到一文中“ICS控件包中的Ping控件”,我怎么没找到Ping控件???在哪?

解决方案 »

  1.   

    自己写一个好了
    unit UnitPing;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, Winsock;
    //////////////////////////////////////////////////////
    //        TPing Copyright (C) BaoMin 1999           //
    //        Author's Email:[email protected]       //
    //        Copyright remains BaoMin, do not remove   //
    //        any Copyright notices.                    //
    //////////////////////////////////////////////////////
    type
    DWORD=LongWord;
    THandle=LongWord;
    PIPOptionInformation = ^TIPOptionInformation;
    TIPOptionInformation =
      record
            TTL: Byte;
          TOS: Byte;
            Flags: Byte;
          OptionsSize: Byte;
            OptionsData: PChar;
      end;PIcmpEchoReply = ^TIcmpEchoReply;
    TIcmpEchoReply =
      record
            Address: DWORD;
            Status: DWORD;
            RTT: DWORD;
            DataSize:Word;
            Reserved: Word;
            Data: Pointer;
            Options: TIPOptionInformation;
      end;function IcmpCreateFile():THandle;stdcall external 'ICMP.dll';
    function IcmpCloseHandle(Handle:THandle):Boolean;stdcall external 'ICMP.dll';
    function IcmpSendEcho(Handle:THandle;DestAddr:DWORD;
             RequestData: Pointer;RequestSize: Word;RequestOptions: PIPOptionInformation;
             ReplyBuffer: Pointer;ReplySize: DWORD;Timeout: DWORD): DWORD;stdcall external 'ICMP.dll';
    procedure ValidCheck();
    procedure FreeWinsock();
    function Ping(IPAddr:String;TimeOut:Word):String;Const
    { Exception Message }
    SInitFailed   = 'Winsock version error';
    SInvalidAddr  = 'Invalid IP Address';
    SNoResponse   = 'No Response';
    STimeOut      = 'Request TimeOut';type
      TFormPing = class(TForm)
        Label1: TLabel;
        Label2: TLabel;
        MemoResult: TMemo;
        EditAddr: TEdit;
        BtnPing: TButton;
        procedure BtnPingClick(Sender: TObject);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      FormPing: TFormPing;
      hICMP:THandle;
    implementation
    {$R *.DFM}
    procedure ValidCheck();
    var
       WSAData:TWSAData;
    begin
         //initiates use of WS2_32.DLL
         if (WSAStartup(MAKEWORD(2,0),WSAData)<>0) then
            raise Exception.Create(SInitFailed);
         hIcmp:=IcmpCreateFile();
         if hICMP=INVALID_HANDLE_VALUE then
            raise Exception.Create('Create ICMP Failed');
    end;
    procedure FreeWinsock();
    begin
         IcmpCloseHandle(hIcmp);
         WSACleanUP;
    end;function Ping(IPAddr:String;TimeOut:Word):String;
    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;
          temp:Integer;
          pIPAddr:Pchar;
    begin
            //get ip
            GetMem(pIPAddr,Length(IPAddr)+1);
            ZeroMemory(pIPAddr,Length(IPAddr)+1);
            StrPCopy(pIPAddr,IPAddr);
            //calc
            FIPAddress := inet_addr(pIPAddr);
            //free it
            FreeMem(pIPAddr);
            //valid check
            if FIPAddress=INADDR_NONE then
            begin
                 result:=SInvalidAddr;//Exit
                 exit;
            end;
    //        WSAAsyncGetHostByAddr()
            //package size
            FSize := 40;
            BufferSize := SizeOf(TICMPEchoReply) + FSize;
            GetMem(pRevData,FSize);
            GetMem(pIPE,BufferSize);
            //prepare data
            FillChar(pIPE^, SizeOf(pIPE^), 0);
            pIPE^.Data := pRevData;
            MyString := 'Ping Digital Data';
            pReqData := PChar(MyString);
            FillChar(IPOpt, Sizeof(IPOpt), 0);
            //max delieve geteway
            IPOpt.TTL := 64;
            //time out
            FTimeOut := TimeOut;
            //go!!!
            temp:=IcmpSendEcho(hICMP,//dll handle
                               FIPAddress,//target
                               pReqData,//data
                               Length(MyString),//data length
                               @IPOpt,//addree of ping option
                               pIPE,//
                               BufferSize,//pack size
                               FTimeOut);//timeout value
            //check result
            if temp=0 then
            begin
                 Result:='Ping Addr:'+IPAddr+' '+SNoResponse;
                 exit;
            end;
            if pReqData^ = pIPE^.Options.OptionsData^ then
            begin
            //show result
            Result:=('Reply from:'+PChar(IPAddr) + ' '
                +'bytes:'+IntToStr(pIPE^.DataSize) + ' '
                +'tims:'+IntToStr(pIPE^.RTT)+ 'ms '
                +'TTL:'+intToStr(pIPE^.Options.TTL));
            end;
            //clear memory
            FreeMem(pRevData);
            FreeMem(pIPE);
    end;procedure TFormPing.BtnPingClick(Sender: TObject);
    var
        pingresult:string;
    begin
         //version check and init
         ValidCheck();
         //update view
         pingresult:=Ping(EditAddr.Text,500);
         MemoResult.Lines.add(pingresult);
         //clear
         FreeWinsock();
    end;procedure TFormPing.FormCreate(Sender: TObject);
    begin
        //update view
        MemoResult.Font.Color:=clHighlightText;
        MemoResult.Font.Name:='Terminal';
        MemoResult.Font.Size:=10;
        MemoResult.Color:= clNone;
    end;end.