public void Execute(object state) { //Connect to the specified server receiveLoopRequired = false; Connect(session); //Execute command ExecuteCommand(CommandString, Credentials.CommandPrompt); //Close Telnet.Close(); }
private void butConnect_Click(object sender, EventArgs e) { try { if (telnet == null) { telnet = new Telnet(); } string strIpAddress = txtIPAddress.Text; int intPort = Convert.ToInt16(txtPort.Text); telnet.Connect(strIpAddress, intPort); if (telnet.Connected == true) { richtxtLogInfo.AppendText("服务器 " + strIpAddress + ":" + intPort + " 连接成功。\r\n"); richtxtLogInfo.AppendText(telnet.WaitFor("login:"******"cq"); richtxtLogInfo.AppendText(telnet.WaitFor("password:"******"windows001"); richtxtLogInfo.AppendText(telnet.WaitFor(">")); telnet.Send("dir"); richtxtLogInfo.AppendText(telnet.WaitFor(">")); telnet.Send("cd Favorites"); richtxtLogInfo.AppendText(telnet.WaitFor(">")); telnet.Send("dir"); richtxtLogInfo.AppendText(telnet.WaitFor(">")); } telnet.Close(); telnet = null; } catch (Exception exc) { richtxtLogInfo.AppendText(exc.Message); } }
private void DealWithSuccessStuff(string nowProgressing, Telnet.Terminal telnetSwitch) { nowUsingItem.LastFlushTime = DateTime.Now; LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "成功,日志:\n" + telnetSwitch.GetHistory); lock (nowUsingItem) { nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "成功\n"; } //成功 RemoveFromErrorList(); if (nowProgressing == nowUsingItem.FlushResult) { lock (nowUsingItem) { nowUsingItem.FlushResult = ""; } } lock (nowUsingItem) { nowUsingItem.LastFlushLog += "\n\n SESSIONLOG:\n\n" + telnetSwitch.GetHistory; } if (telnetSwitch.IsOpenConnection()) { if (telnetSwitch.SendLogout() == false) { lock (nowUsingItem) { nowUsingItem.FlushResult = "请求注销失败"; } throw new Exception(); } telnetSwitch.Close(); } }
private void DealWithErrorStuff(Telnet.Terminal telnetSwitch) { string infomationToWriteInfo = nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + nowUsingItem.FlushResult; if (telnetSwitch.VirtualScreen != null) { infomationToWriteInfo += telnetSwitch.VirtualScreen.Hardcopy().Trim(); } else { infomationToWriteInfo += "=====NULL====="; } LogInToEvent.WriteInfo(infomationToWriteInfo); LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "失败,日志:\n" + telnetSwitch.GetHistory); RemoveFromDisableListForErrorOcour(); AddsToErrorList(); lock (nowUsingItem) { nowUsingItem.LastFlushLog = telnetSwitch.GetHistory; } nowUsingItem.LastFlushTime = DateTime.Now; if (telnetSwitch.IsOpenConnection()) { if (telnetSwitch.SendLogout() == false) { lock (nowUsingItem) { nowUsingItem.FlushResult = "请求注销失败"; } } telnetSwitch.Close(); } }
/// <summary> /// 退出操作 /// </summary> public void Quit() { telnet.Close(); telnet = null; }
private void DealWithErrorStuff(Telnet.Terminal telnetSwitch) { string infomationToWriteInfo = nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + nowUsingItem.FlushResult; if (telnetSwitch.VirtualScreen != null) { infomationToWriteInfo += telnetSwitch.VirtualScreen.Hardcopy().Trim(); } else { infomationToWriteInfo += "=====NULL====="; } LogInToEvent.WriteInfo(infomationToWriteInfo); LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "失败,日志:\n" + telnetSwitch.GetHistory); lock (nowUsingItem) { nowUsingItem.LastFlushLog += "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n===========================\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"; nowUsingItem.LastFlushLog += infomationToWriteInfo; nowUsingItem.LastFlushLog += telnetSwitch.GetHistory; nowUsingItem.LastFlushLog += "\r\n错误返回"; nowUsingItem.FlushResult = "在恢复过程中出现错误"; } nowUsingItem.LastFlushTime = DateTime.Now; if (telnetSwitch.IsOpenConnection()) { if (telnetSwitch.SendLogout() == false) { lock (nowUsingItem) { nowUsingItem.FlushResult = "请求注销失败"; } } telnetSwitch.Close(); } lock (nowUsingItem) { nowUsingItem.FlushResult = "在试图恢复时发生错误"; } }