private void SendLoginPassword_HighPriv(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch) { //enable密码 LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "等待要求enable密码"); lock (nowUsingItem) { nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "等待要求enable密码\n"; } try { telnetSwitch.WaitForString(whatTypeOfSwitch.PromptForEnablePassword); } catch (Exception e) { LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + e.ToString()); lock (nowUsingItem) { nowUsingItem.FlushResult = "没有提示输入enable密码/enable用户名错误?"; } throw new Exception(); } lock (nowUsingItem) { nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "发送enable密码\n"; } if (!telnetSwitch.SendResponse(nowUsingItem.EnablePassword, true)) { lock (nowUsingItem) { nowUsingItem.FlushResult = "错误:发送enable密码失败"; } throw new Exception(); } if (!telnetSwitch.WaitForChangedScreen()) { lock (nowUsingItem) { nowUsingItem.FlushResult = "错误:WaitForChangedScreen返回false"; } throw new Exception(); } }
private void MakeSureEnableSuccess(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch) { try { telnetSwitch.WaitForString(whatTypeOfSwitch.PromptForCommandAfterEnable); } catch (Exception e) { LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + e.ToString()); lock (nowUsingItem) { nowUsingItem.FlushResult = "没有提示enable提示符,enable 密码错误?"; } throw new Exception(); } }
private void SendLoginUserNameIfNeeded(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch) { if (whatTypeOfSwitch.IsThisSwitchNeedsOfUserName) { LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "要求登录用户名"); lock (nowUsingItem) { nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "要求登录用户名\n"; } try { telnetSwitch.WaitForString(whatTypeOfSwitch.PromptForUserName); } catch (Exception e) { lock (nowUsingItem) { nowUsingItem.FlushResult = "要求用户名时遇到异常-" + e.ToString(); } LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + e.ToString()); throw new Exception(); } if (!telnetSwitch.SendResponse(nowUsingItem.UserName, true)) { lock (nowUsingItem) { nowUsingItem.FlushResult = "未发送用户名"; } throw new Exception(); } if (!telnetSwitch.WaitForChangedScreen()) { lock (nowUsingItem) { nowUsingItem.FlushResult = "等待用户名结果失败"; } throw new Exception(); } } }
private void MakeSureLowPrivIsGood(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch) { //确认登录密码正确性 LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "确认登录密码正确性"); nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "确认登录密码正确性\n"; try { telnetSwitch.WaitForString(whatTypeOfSwitch.PromptForCommandBeforeEnable); } catch (Exception e) { LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + e.ToString()); lock (nowUsingItem) { nowUsingItem.FlushResult = "登录密码错误"; } throw new Exception(); } }
private void SendLoginPassword_LowPriv(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch) { LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "要求登录密码"); lock (nowUsingItem) { nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "要求登录密码\n"; } try { telnetSwitch.WaitForString(whatTypeOfSwitch.PromptForPassword); } catch (Exception e) { LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + e.ToString()); lock (nowUsingItem) { nowUsingItem.FlushResult = "没有要求密码或密码请求字符串不正确"; } throw new Exception(); } LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "发送登录密码"); lock (nowUsingItem) { nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "发送登录密码\n"; } if (!telnetSwitch.SendResponse(nowUsingItem.Password, true)) { lock (nowUsingItem) { nowUsingItem.FlushResult = "发送密码失败"; } throw new Exception(); } if (!telnetSwitch.WaitForChangedScreen()) { lock (nowUsingItem) { nowUsingItem.FlushResult = "发送密码后没有响应"; } throw new Exception(); } }
private void SendEnableUserNameIfNeeded(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch) { //enable登录过程 if (whatTypeOfSwitch.IsThisSwitchNeedsOfEnableUserName) { LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "等待要求enable用户名登录"); nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "等待要求enable用户名登录\n"; try { telnetSwitch.WaitForString(whatTypeOfSwitch.PromptForEnableUserName); } catch (Exception e) { LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + e.ToString()); lock (nowUsingItem) { nowUsingItem.FlushResult = "没有提示输入enable用户名"; } throw new Exception(); } lock (nowUsingItem) { nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "发送enable用户名\n"; } if (!telnetSwitch.SendResponse(nowUsingItem.EnableUsername, true)) { lock (nowUsingItem) { nowUsingItem.FlushResult = "发送enable用户名失败"; } throw new Exception(); } if (!telnetSwitch.WaitForChangedScreen()) { lock (nowUsingItem) { nowUsingItem.FlushResult = "发送enable用户名后没有响应"; } throw new Exception(); } } }