网中有一台202.32.56.112。我想测一下跟它通不通。怎么能做到。最好说明原理和实现方法。分不够。再加+++在线等。。

解决方案 »

  1.   

    ping -t 202.32.56.112-t 加后面 Linux 下就不行了
      

  2.   

    ping命令--详细帮助 
    校验与远程计算机或本地计算机的连接。只有在安装 TCP/IP 协议之后才能使用该命令。ping [-t] [-a] [-n count] [-l length] [-f] [-i ttl] [-v tos] [-r count] [-s count] [[-j computer-list] | [-k computer-list]] [-w timeout] destination-list 参数 -t 校验与指定计算机的连接,直到用户中断。 -a 将地址解析为计算机名。 -n count 发送由 count 指定数量的 ECHO 报文,默认值为 4。 -l length 发送包含由 length 指定数据长度的 ECHO 报文。默认值为 64 字节,最大值为 8192 字节。 -f 在包中发送“不分段”标志。该包将不被路由上的网关分段。 -i ttl 将“生存时间”字段设置为 ttl 指定的数值。 -v tos 将“服务类型”字段设置为 tos 指定的数值。 -r count 在“记录路由”字段中记录发出报文和返回报文的路由。指定的 Count 值最小可以是 1,最大可以是 9 。 -s count 指定由 count 指定的转发次数的时间邮票。 -j computer-list 经过由 computer-list 指定的计算机列表的路由报文。中间网关可能分隔连续的计算机(松散的源路由)。允许的最大 IP 地址数目是 9 。 -k computer-list 经过由 computer-list 指定的计算机列表的路由报文。中间网关可能分隔连续的计算机(严格源路由)。允许的最大 IP 地址数目是 9 。 -w timeout 以毫秒为单位指定超时间隔。 destination-list 指定要校验连接的远程计算机。 关于 Ping 的详细信息 Ping--注意 Ping 命令通过向计算机发送 ICMP 回应报文并且监听回应报文的返回,以校验与远程计算机或本地计算机的连接。对于每个发送报文, Ping 最多等待 1 秒,并打印发送和接收把报文的数量。比较每个接收报文和发送报文,以校验其有效性。默认情况下,发送四个回应报文,每个报文包含 64 字节的数据(周期性的大写字母序列)。可以使用 Ping 实用程序测试计算机名和 IP 地址。如果能够成功校验 IP 地址却不能成功校验计算机名,则说明名称解析存在问题。这种情况下,要保证在本地 HOSTS 文件中或 DNS 数据库中存在要查询的计算机名。下面显示 Ping 输出的示例:(Windows用户可用:开始->运行,输入"command" 调出command窗口使用此命令)C:\>ping ds.internic.netPinging ds.internic.net [192.20.239.132] with 32 bytes of data:Reply from 192.20.239.132: bytes=32 time=101ms TTL=243Reply from 192.20.239.132: bytes=32 time=100ms TTL=243Reply from 192.20.239.132: bytes=32 time=120ms TTL=243Reply from 192.20.239.132: bytes=32 time=120ms TTL=243 
      

  3.   

    同上意见,PING在UNIX或是LINUX环境下必须带次数,否则它会一直干下去,不会停止。
      

  4.   

    http://www.delphipages.com/news/detaildocs.cfm?ID=93unit Ping;interfaceuses  Windows, SysUtils, Classes;type  TSunB = packed record    s_b1, s_b2, s_b3, s_b4: byte;  end;  TSunW = packed record    s_w1, s_w2: word;  end;  PIPAddr = ^TIPAddr;  TIPAddr = record    case integer of      0: (S_un_b: TSunB);      1: (S_un_w: TSunW);      2: (S_addr: longword);  end; IPAddr = TIPAddr;function IcmpCreateFile : THandle; stdcall; external 'icmp.dll';function IcmpCloseHandle (icmpHandle : THandle) : boolean; stdcall; external 'icmp.dll'function IcmpSendEcho (IcmpHandle : THandle; DestinationAddress : IPAddr;    RequestData : Pointer; RequestSize : Smallint;    RequestOptions : pointer;    ReplyBuffer : Pointer;    ReplySize : DWORD;    Timeout : DWORD) : DWORD; stdcall; external 'icmp.dll';function Ping(InetAddress : string) : boolean;implementationuses  WinSock;function Fetch(var AInput: string; const ADelim: string = ' '; const ADelete: Boolean = true) : string;var  iPos: Integer;begin  if ADelim = #0 then begin    // AnsiPos does not work with #0    iPos := Pos(ADelim, AInput);  end else begin    iPos := Pos(ADelim, AInput);  end;  if iPos = 0 then begin    Result := AInput;    if ADelete then begin      AInput := '';    end;  end else begin    result := Copy(AInput, 1, iPos - 1);    if ADelete then begin      Delete(AInput, 1, iPos + Length(ADelim) - 1);    end;  end;end;procedure TranslateStringToTInAddr(AIP: string; var AInAddr);var  phe: PHostEnt;  pac: PChar;  GInitData: TWSAData;begin  WSAStartup($101, GInitData);  try    phe := GetHostByName(PChar(AIP));    if Assigned(phe) then    begin      pac := phe^.h_addr_list^;      if Assigned(pac) then      begin        with TIPAddr(AInAddr).S_un_b do begin          s_b1 := Byte(pac[0]);          s_b2 := Byte(pac[1]);          s_b3 := Byte(pac[2]);          s_b4 := Byte(pac[3]);        end;      end      else      begin        raise Exception.Create('Error getting IP from HostName');      end;    end    else    begin      raise Exception.Create('Error getting HostName');    end;  except    FillChar(AInAddr, SizeOf(AInAddr), #0);  end;  WSACleanup;end;function Ping(InetAddress : string) : boolean;var Handle : THandle; InAddr : IPAddr; DW : DWORD; rep : array[1..128] of byte;begin  result := false;  Handle := IcmpCreateFile;  if Handle = INVALID_HANDLE_VALUE then   Exit;  TranslateStringToTInAddr(InetAddress, InAddr);  DW := IcmpSendEcho(Handle, InAddr, nil, 0, nil, @rep, 128, 0);  Result := (DW <> 0);  IcmpCloseHandle(Handle);end;end.
      

  5.   

    是编程实现。不是用PING。大家帮忙。
      

  6.   

    可以使用delphi7的idicmpclient组件,楼主去好好研究!
      

  7.   

    我有一个 源程序买书时 带来的 PING 的  
    一个 Edit1 一个Button1  一个 StringGrid1 以下代码
    unit ping;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      Grids,  winsock, StdCtrls;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;
                               RequestData: Pointer;
                               RequestSize: Word;
                               RequestOptions: PIPOptionInformation;
                               ReplyBuffer: Pointer;
                               ReplySize: DWord;
                               Timeout: DWord): DWord; stdcall;type
      TForm1 = class(TForm)
        StringGrid1: TStringGrid;
        Edit1: TEdit;
        Button1: TButton;
        Label1: TLabel;
        procedure FormCreate(Sender: TObject);
        procedure Button1Click(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        { Private declarations }
      hICMP: THANDLE;
      IcmpCreateFile : TIcmpCreateFile;
      IcmpCloseHandle:TIcmpCloseHandle;
      IcmpSendEcho: TIcmpSendEcho;
      line:integer;  public
        { Public declarations }
      hICMPdll: HMODULE;
      end;var
      Form1: TForm1;
    implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
    begin
      hICMPdll := LoadLibrary('icmp.dll');
      @ICMPCreateFile:= GetProcAddress(hICMPdll, 'IcmpCreateFile');
      @IcmpCloseHandle := GetProcAddress(hICMPdll, 'IcmpCloseHandle');
      @IcmpSendEcho := GetProcAddress(hICMPdll, 'IcmpSendEcho');
      hICMP := IcmpCreateFile;
      StringGrid1.Cells[0,0]:=' ';
      StringGrid1.Cells[1,0]:='返回地址';
      StringGrid1.cells[2,0]:='返回数据包大小';
      StringGrid1.Cells[3,0]:='RTT(Round-Trip-Time)';
      line:=1;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      IPOpt:TIPOptionInformation;
      FIPAddress:DWORD;
      pReqData,pRevData:PChar;
      pIPE:PIcmpEchoReply;
      FSize: DWORD;
      MyString:string;
      FTimeOut:DWORD;
      BufferSize:DWORD;
    begin
      if Edit1.Text <> '' then
      begin
        FIPAddress:=inet_addr(PChar(Edit1.Text));
        if Fipaddress=INADDR_NONE then
         Messagebox(self.handle,'地址无效','Ping32',64)
        else
        begin
            FSize:=80;
            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 :=500;
            IcmpSendEcho(hICMP, FIPAddress, pReqData, Length(MyString),@IPOpt, pIPE,
            BufferSize, FTimeOut);
            try
              try
                if pReqData^ = pIPE^.Options.OptionsData^ then
                  with StringGrid1 do
                  begin
                    if line>1 then rowcount:=line+1;
                    cells[0,line]:=inttoStr(line);
                    cells[1,line]:=Edit1.Text;
                    cells[2,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 TForm1.FormDestroy(Sender: TObject);
    begin
      icmpclosehandle(hicmp);
      freelibrary(hicmpdll);
    end;end.