Ejemplo n.º 1
0
        public void SSHLogon()
        {
            execute = new Parser();
            while (true)
            {
                sb.Append("\n");
                string VCID;
                string vcid = null;
                VCIDArray = new ArrayList();
                index = 0;
                string comman = null;

                //using (StreamReader reader1 = new StreamReader("list2.txt"))
                //{
                //    while ((VCID = reader1.ReadLine()) != null)
                //    {
                //        VCIDArray.Add(VCID);
                //    }
                //}

                //using (StreamReader reader = new StreamReader("IP2Connect2.txt"))
                //{
                //    while ((ipaddress = reader.ReadLine()) != null)
                //    {
                //        //originalSentence = list1;
                //        //ipaddress = findIP(ref originalSentence);
                //        if (ipaddress != null)
                //        {
                using (StreamReader reader = new StreamReader("IP2Connect2.txt"))
                {
                    while ((ipaddress = reader.ReadLine()) != null)
                    {

                        skipIPandDebug = false;
                        ArrayList allcommands = null;
                        allcommands = new ArrayList();

                        //1st command
                        allcommands.Add("ssh " + ipaddress);
                        //allcommands.Add("jkjenkins");
                        //2nd command
                        //allcommands.Add(userRtr.ToString() +"\r");

                        //3rd command
                        //allcommands.Add(user.ToString());

                        allcommands.Add(pwd.ToString() + "\r");

                        //get VCID or VLAN
                        int numbers = 0;

                        getCommands = new GetCommands();
                        for (index = 0; index < 4; index++)
                        {
                            int numofcommands = allcommands.Count;
                            //index++;
                            if (index >= 2)
                            {
                                comman = getCommands.Commands[numbers];
                                allcommands.Insert(index, comman + "\r");
                                numbers++;
                            }

                            //if (index == 2)
                            //{
                            //     comman = getCommands.Commands[0];

                            //    allcommands.Insert(index, comman + "\r");

                            //}
                            //if (index == 3)
                            //{

                            //    if (getCommands.EciORjun == true)
                            //    {
                            //        getCommands.checkECIorJUN();
                            //        if (getCommands.JUN)
                            //            comman = getCommands.Commands[2];
                            //        if (getCommands.ECI)
                            //            comman = getCommands.Commands[1];
                            //    }
                            //    else
                            //    {
                            //        comman = getCommands.Commands[1];
                            //    }
                            //    allcommands.Insert(index, comman + " " + theObj + "\r");
                            //}
                            //if (index == 4)
                            //{
                            //    if (getCommands.EciORjun == true)
                            //    {
                            //        getCommands.checkECIorJUN();
                            //        if (getCommands.JUN)
                            //            comman = getCommands.Commands[3];
                            //        if (getCommands.ECI)
                            //            comman = getCommands.Commands[3];
                            //    }
                            //    else
                            //    {
                            //        comman = getCommands.Commands[2];
                            //    }
                            //    allcommands.Insert(index, comman + "\r");
                            //}
                            //if (index == 5)
                            //{
                            //    if (getCommands.EciORjun == true)
                            //    {
                            //        comman = "";
                            //    }
                            //    else
                            //    {
                            //        comman = getCommands.Commands[3];
                            //    }
                            //    allcommands.Insert(index, comman + "\r");
                            //}
                            //if (index == 6)
                            //{
                            //    if (getCommands.EciORjun == true)
                            //    {
                            //        comman = "";
                            //    }
                            //    else
                            //    {
                            //        comman = getCommands.Commands[4];
                            //    }
                            //    allcommands.Insert(index, comman + "\r");
                            //}

                            sb.Append(allcommands[index]);
                            sb.Append("\n");
                            string command = sb.ToString();
                            success = ssh.ChannelSendString(channelNum, sb.ToString(), "ansi");

                            if (success != true)
                            {
                                Console.WriteLine(ssh.LastErrorText + "\r\n");
                                // Read so we can see the error before the console closes.
                                string x = Console.ReadLine();
                                return;
                            }
                            else
                            {
                                returnInfo();
                                sb.Length = 0;
                                if (skipIPandDebug)
                                {
                                    index = 0;
                                    SkipandDebug(ipaddress, vcid);
                                    goto skipping;
                                }
                                //if (index == numofcommands)
                                //    index = 0;
                            }

                        }
                        //if (index == 5)
                        //{
                        //    break;
                        //}
                    }

                }
            skipping: ;
            }
        }
Ejemplo n.º 2
0
        public void SSHLogon()
        {
            execute = new Parser();
            while (true)
            {

                index = 0;
                        //originalSentence = list1;
                        //ipaddress = findIP(ref originalSentence);
                if (ipaddress != null)
                {

                    skipIPandDebug = false;
                    ArrayList allcommands = null;
                    allcommands = new ArrayList();

                    allcommands.Add("ssh " + ipaddress + "\r");
                    allcommands.Add(pwd.ToString() + "\r");
                    allcommands.Add("terminal length 0");
                    allcommands.Add("show version");
                    allcommands.Add("terminal length 57");
                    allcommands.Add("exit \r");

                    for (index = 0; index < allcommands.Count; index++)
                    {
                        int numofcommands = allcommands.Count;
                        //index++;
                        sb.Append(allcommands[index]);
                        sb.Append("\n");
                        string command = sb.ToString();
                        success = ssh.ChannelSendString(channelNum, sb.ToString(), "ansi");

                        if (success != true)
                        {
                            Console.WriteLine(ssh.LastErrorText + "\r\n");
                            // Read so we can see the error before the console closes.
                            string x = Console.ReadLine();
                            return;
                        }
                        else
                        {
                            returnInfo();
                            sb.Length = 0;
                            if (skipIPandDebug)
                            {
                                index = 0;
                                SkipandDebug(ipaddress);
                                goto skipping;
                            }
                            //if (index == numofcommands)
                            //    index = 0;
                        }

                    }
                    if (index == allcommands.Count)
                    {
                        skipIPandDebug = true;
                        return;
                    }
                }
            }
            skipping: ;
        }