示例#1
0
        private void btnChange_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            try {
                tc       = new TelnetConnection(AuthVars.HOSTNAME, AuthVars.PORT);
                response = tc.Login(AuthVars.USERNAME, AuthVars.PASSWORD, AuthVars.TIMEOUT);

                string prompt = response.TrimEnd();
                prompt = response.Substring(prompt.Length - 1, 1);
                if (prompt != "$" && prompt != ">")
                {
                    throw new Exception("Connection failed");
                }

                if (tc.IsConnected)
                {
                    tc.WriteLine(string.Format(Command.SetMacAddFormat, txtMac.Text.Trim()));
                    textBox2.AppendText(tc.Read());
                    tc.WriteLine(Command.RestoreDefault);
                    textBox2.AppendText(tc.Read());
                    this.Close();
                }
                else
                {
                    lblStatus.Text      = "      Not connected!";
                    lblStatus.ForeColor = Color.Red;
                }
            } catch {
                lblStatus.Text      = "      Exception Error!";
                lblStatus.ForeColor = Color.Red;
            } finally {
                Cursor.Current = Cursors.Default;
            }
        }
示例#2
0
 void btnCmdDisplay_Click(object sender, EventArgs e)
 {
     txtResponse.Text = String.Empty;
     try {
         Cursor.Current = Cursors.WaitCursor;
         if (tc.IsConnected)
         {
             tc.WriteLine(Command.BasicConfig);
             txtResponse.AppendText(tc.Read());
             SetResponseOK("Basic Configuration.");
         }
         else
         {
             SetConnection(false);
         }
     } catch {
         SetErrorStatus("Error in displaying basic configuration.", true);
     } finally {
         Cursor.Current = Cursors.Default;
     }
 }