Пример #1
0
        // анализ приветствия модема
        private GreetingInfo GreetingAnalise()
        {
            GreetingInfo rezult = GreetingInfo.None;

            if (RespString.IndexOf("QDSL") > 0)
            {
                rezult = GreetingInfo.Qtech;
                if (RespString.IndexOf("QDSL-1040rev.B1") > 0)
                {
                    rezult = GreetingInfo.Q1040_B1;
                }

                return(rezult);
            }


            return(rezult);
        }
Пример #2
0
        //      ######     #######     ########   ##         ##      ###      ############  ##########
        //      #######    ########    ########   ##         ##     ## ##     ############  ##########
        //      ##    ##   ##     ##      ##       ##       ##     ##   ##         ##       ##
        //      ##    ##   ##     ##      ##       ##       ##     ##   ##         ##       ##
        //      ##    ##   ##    ##       ##        ##     ##     ##     ##        ##       ########
        //      #######    #######        ##        ##     ##     #########        ##       #######
        //      ######     ####           ##         ##   ##     ###########       ##       ##
        //      ##         ##  ##         ##         ##   ##     ##       ##       ##       ##
        //      ##         ##    ##    ########       ## ##     ##         ##      ##       #########
        //      ##         ##     ##   ########        ###      ##         ##      ##       ##########
        private void Connect()
        {
            // создаем новый сокет для телнета
            if (TlnSocket == null)
            {
                TlnSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            }

            // пытаемся заТелнениться
            //this.statBar.Text = "Подлкючаемся...";
            if (TryConnectTelnet() == false)
            {
                MessageBox.Show("Не удалось подключиться.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                // закрываем телнет сокет и осовобождаем ресурсы
                CloseTelnet();
                return;
            }


            // получить приглашение на ввод логина
            if (PleaseLogIn() == false)
            {
                MessageBox.Show("Превышен таймаут ожидания.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                // закрываем телнет сокет и осовобождаем ресурсы
                CloseTelnet();
                return;
            }


            // анализ приветствия модема
            GreetingInfo inf = GreetingAnalise();

            if (inf == GreetingInfo.Q1040_B1)
            {
                MIS.ModemNum = 0;
            }


            // авторизация
            if (inf == GreetingInfo.Q1040_B1)
            {
                MIS.ModemNum = 0;
                if (AutorizQtech() == false)
                {
                    MessageBox.Show("Не удалось авторизоваться", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    // закрываем телнет сокет и осовобождаем ресурсы
                    CloseTelnet();
                    return;
                }
                MIS.SoftNum = GetSoftIndexQTech();
            }
            else if (inf == GreetingInfo.Qtech)
            {
                if (AutorizQtech() == false)
                {
                    MessageBox.Show("Не удалось авторизоваться", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    CloseTelnet();
                    return;
                }
                MIS.SoftNum = GetSoftIndexQTech();
            }
            else    // D-Link и прочие
            {
                if (AutorizDlink() == false)
                {
                    MessageBox.Show("Не удалось авторизоваться", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    CloseTelnet();
                    return;
                }

                // читаем с паузами
                int Ln  = RespString.Length;
                int Ln2 = Ln;
                do
                {
                    Ln = Ln2;
                    Thread.Sleep(100);
                    RespString += ReadResponseBuffer();
                    Ln2         = RespString.Length;
                } while (Ln2 > Ln);

                // анализ чего ответил после авторизации
                if (RespString.IndexOf("NAME=DSL-2540U") > 0 ||
                    RespString.IndexOf("NAME=DSL_2540") > 0)
                {
                    MIS.ModemNum = 1;
                    if (RespString.IndexOf("VERSION=1.0.27") > 0)
                    {
                        MIS.SoftNum = 0;
                    }
                    else if (RespString.IndexOf("VERSION=1.0.28") > 0)
                    {
                        MIS.SoftNum = 1;
                    }
                    else if (RespString.IndexOf("VERSION=1.0.30") > 0)
                    {
                        MIS.SoftNum = 2;
                    }
                    else
                    {
                        MIS.SoftNum = -1;   // неизвестная прошивка
                    }
                }
                else if (RespString.IndexOf("NAME=DSL-2500U") > 0)
                {
                    MIS.ModemNum = 2;
                    if (RespString.IndexOf("VERSION=1.0.47") > 0)
                    {
                        MIS.SoftNum = 0;
                    }
                    else if (RespString.IndexOf("VERSION=1.0.49") > 0)
                    {
                        MIS.SoftNum = 1;
                    }
                    else
                    {
                        MIS.SoftNum = -1;   // неизвестная прошивка
                    }
                }

                else if (RespString.IndexOf("NAME=DSL-2520U") > 0)
                {
                    MIS.ModemNum = 3;
                    if (RespString.IndexOf("VERSION=1.0.4") > 0)
                    {
                        MIS.SoftNum = 0;
                    }
                    else
                    {
                        MIS.SoftNum = -1;   // неизвестная прошивка
                    }
                }
                else
                {
                    // неизвестный модем
                }

                //MIS.SoftNum = GetSoftIndex();
            }


            CloseTelnet();
        }