我用telnet命令检测端口,可是在程序中我怎么判断端口检测是成功还是失败Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.
C:\Documents and Settings\Administrator>telnet 127.0.0.1 2000
正在连接到127.0.0.1...不能打开到主机的连接, 在端口 2000: 连接失败在 命令行是可以看出来检测结果,可是我怎么在程序中知道

解决方案 »

  1.   

    idTelnet1.Host := '127.0.0.1';
    idTelnet1.Port := 2000;
    try
      idTelnet1.Connect(10000);
      ShowMessage('Connected');
    except
      ShowMessage('Connect fail.');
    end;
      

  2.   

    idTelnet1.Host := '127.0.0.1'; 
    idTelnet1.Port := 2000; 
    try 
      idTelnet1.Connect(10000); 
      if idTelnet1.Connected then
        ShowMessage('Connected'); 
    except 
      ShowMessage('Connect fail.'); 
    end;
      

  3.   

    用这个控件是可以的,我想直接用 
    winexec(pchar('cmd.exe /c telnet ip 端口'),sw_hide);
    不知道有没有办法