コード例 #1
0
        private void CheckForDisableStringInData(DisableGetObjects.Setting_SwitchType whatTypeOfSwitch, string dataContains, out bool isthisswitchhasdisable, out string flushResult)
        {
            LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "取到项目:\n" + dataContains);
            var lines = dataContains.Split('\n');

            LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "开始检查项目列表:共" + lines.Length + "项");
            lock (nowUsingItem)
            { nowUsingItem.LastFlushLog += "\n" + nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "开始检查项目列表:共" + lines.Length.ToString() + "项\n"; }
            isthisswitchhasdisable = false;
            //保存disable
            flushResult = "";
            foreach (var t in lines)
            {
                LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "检查项目_disable\n" + t + "查找" + whatTypeOfSwitch.ScreeningStringForDisableItem);
                if (t.ToLower().Contains(whatTypeOfSwitch.ScreeningStringForDisableItem.ToLower()))
                {
                    LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "检查项目_port\n" + t + "查找" + whatTypeOfSwitch.ScreeningStringForPortLine);
                    if (t.ToLower().Contains(whatTypeOfSwitch.ScreeningStringForPortLine.ToLower()))
                    {
                        //找到了disable的项
                        LogInToEvent.WriteDebug(nowUsingItem.Name + "/" + nowUsingItem.IpAddress + "-" + "DISABLE:" + t);
                        flushResult           += t + "\n";
                        isthisswitchhasdisable = true;
                    }
                }
            }
        }
コード例 #2
0
        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();
            }
        }
コード例 #3
0
 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();
     }
 }
コード例 #4
0
 private void GetIntoTerminalConfigMode(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch)
 {
     nowUsingItem.LastFlushLog += "\n GetIntoTerminalConfigMode ";
     nowUsingItem.LastFlushLog += "\n 发送:" + whatTypeOfSwitch.SwitchCommandForConfigMode + "\r\n";
     if (!telnetSwitch.SendResponse(whatTypeOfSwitch.SwitchCommandForConfigMode, true))
     {
         lock (nowUsingItem)
         {
             nowUsingItem.LastFlushLog += "\n" + "进入终端配置模式失败\n";
         }
         throw new Exception();
     }
     for (int i = 0; i < 20; ++i)
     {
         telnetSwitch.SendResponse(" ", true);
     }
 }
コード例 #5
0
 private void SendErrdisableRecoveryCommand(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch)
 {
     nowUsingItem.LastFlushLog += "\n SendErrdisableRecoveryCommand ";
     nowUsingItem.LastFlushLog += "\n 发送:" + whatTypeOfSwitch.SwitchCommandForRecoving + "\r\n";
     if (!telnetSwitch.SendResponse(whatTypeOfSwitch.SwitchCommandForRecoving, true))
     {
         lock (nowUsingItem)
         {
             nowUsingItem.LastFlushLog += "\n" + "发送恢复命令失败\n";
         }
         throw new Exception();
     }
     for (int i = 0; i < 20; ++i)
     {
         telnetSwitch.SendResponse(" ", true);
     }
 }
コード例 #6
0
        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();
                }
            }
        }
コード例 #7
0
 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();
     }
 }
コード例 #8
0
 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();
     }
 }
コード例 #9
0
 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();
         }
     }
 }
コード例 #10
0
 private void SendEndToSuperModeCommand(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch)
 {
     lock (nowUsingItem)
     {
         nowUsingItem.LastFlushLog += "\n SendEndToSuperModeCommand \r\n";
         nowUsingItem.LastFlushLog += "\n 发送:" + whatTypeOfSwitch.SwitchCommandForEndConfig + "\r\n";
     }
     if (!telnetSwitch.SendResponse(whatTypeOfSwitch.SwitchCommandForEndConfig, true))
     {
         lock (nowUsingItem)
         {
             nowUsingItem.LastFlushLog += "\n" + "回到普通命令提示模式失败\n";
         }
         throw new Exception();
     }
     for (int i = 0; i < 20; ++i)
     {
         telnetSwitch.SendResponse(" ", true);
     }
 }
コード例 #11
0
        private void WaitForAllSwitchStatusTransmited(Telnet.Terminal telnetSwitch, DisableGetObjects.Setting_SwitchType whatTypeOfSwitch)
        {
            //大量交换机显示==more==信息,因此需要等待命令行
            //added @ 2012 05 20 by sc
            for (int counter = 0; counter < 20; ++counter)
            {
                if (!telnetSwitch.SendResponse(" ", false))
                {
                    lock (nowUsingItem)
                    { nowUsingItem.FlushResult = "发送等待命令行参数的请求失败"; }
                    throw new Exception();
                }
            }

            ///最大尝试次数
            const int MAXIMUM_TRY_COUNT = 20;

            for (int currectTry = 0; currectTry <= MAXIMUM_TRY_COUNT; ++currectTry)
            {
                telnetSwitch.WaitForChangedScreen();

                //若是屏幕上没有出现命令提示符
                try
                {
                    if (telnetSwitch.VirtualScreen.FindOnScreen(whatTypeOfSwitch.PromptForCommandAfterEnable, false) != null)
                    {
                        break;
                    }
                }
                catch (NullReferenceException)
                {
                    lock (nowUsingItem)
                    { nowUsingItem.FlushResult = "发送请求命令行参数的请求中,连接断开"; }
                    throw new Exception();
                }
                catch (Exception)
                {
                    lock (nowUsingItem)
                    { nowUsingItem.FlushResult = "发送请求命令行参数的请求失败"; }
                    throw new Exception();
                }

                if (currectTry == MAXIMUM_TRY_COUNT)
                {
                    //到达最大重试门限
                    lock (nowUsingItem)
                    {
                        nowUsingItem.LastFlushLog += "\n到达取得数据最大门限\n";
                    }
                }
                else
                {
                    //发送空格以及两个回车
                    if (!telnetSwitch.SendResponse(" ", true))
                    {
                        lock (nowUsingItem)
                        { nowUsingItem.FlushResult = "发送等待命令行参数的请求失败-1"; }
                        throw new Exception();
                    }
                }
            }
        }