using System.Net.Sockets;
    
    using System.Net;
   
    //完成TELNET
    
    private static string cmdTelnet(string strIP,int strNum)
    
    {
    
    
    string strTelnet;
    try
    
    {
    
    
    IPAddress ip = IPAddress.Parse(strIP);
    
    IPEndPoint point = new IPEndPoint(ip, strNum);
    
    Socket sock = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
    
    sock.Connect(point);
    
    strTelnet = string.Format(“连接端口{0} 成功!”,point);
    
    }
    
    catch(SocketException e)
    
    {
    
    if (e.ErrorCode != 10061)
    
    {
    
    
    MessageBox.Show(e.Message.ToString(), “提示”, MessageBoxButtons.OK);
    
    }
    
    strTelnet = string.Format(“连接{0} 失败”, strIP + “:” + strNum);
    
    }
    
    return strTelnet;
    
    }
   
 
