Exemple #1
0
 public broad(string broad_address, string login_name, string login_pwd, string program)
 {
     string f;
     change_state_to_disconnect();
     log = "Log:\r\n";
     if (debug == true)
     {
         change_state_to_connect();
         return;
     }
     shell = new Terminal(broad_address);
     shell.Connect(); // physcial connection
     do
     {
         f = shell.WaitForString("Login",false,200);
         if (f==null)
             break; // this little clumsy line is better to watch in the debugger
         shell.SendResponse(login_name, true);	// send username
         f = shell.WaitForString("Password");
         if (f == null)
             break;
         shell.SendResponse(login_pwd, true);	// send password
         f = shell.WaitForString("$");			// bash
         if (f == null)
             break;
         shell.SendResponse(program, true);	// send password
         f = shell.WaitForString("Meteroi shell>");			// program shell
         if (f == null)
             break;
         change_state_to_connect();
     } while (false);
     log += shell.VirtualScreen.Hardcopy().TrimEnd();
     log += "\r\n";
 }
Exemple #2
0
        public void SetRouter(string cmd)
        {
            Terminal tn = new Terminal("192.168.1.1", 23, 10, 80, 40); // hostname, port, timeout [s], width, height
            string Text="";
            tn.Connect(); // physical connection
            do
            {
                string f = tn.WaitForString("Login");
                if (f == null)
                    break; // this little clumsy line is better to watch in the debugger
                Text += tn.VirtualScreen.Hardcopy().TrimEnd();
                tn.SendResponse("admin", true);	// send username
                f = tn.WaitForString("Password");
                if (f == null)
                    break;
                Text += tn.VirtualScreen.Hardcopy().TrimEnd();
                tn.SendResponse("admin", true);	// send password
                f = tn.WaitForString("#");
                if (f == null)
                    break;

                if (cmd == "online")
                {
                    tn.SendResponse("nvram set wan_way 1", true);	// send Shell command
                    if (tn.WaitForChangedScreen())
                        Text = tn.VirtualScreen.Hardcopy().TrimEnd();
                }
                if (cmd == "offline")
                {
                    tn.SendResponse("nvram set wan_way 0", true);	// send Shell command
                    if (tn.WaitForChangedScreen())
                        Text = tn.VirtualScreen.Hardcopy().TrimEnd();
                }
                tn.SendResponse("nvram commit", true);	// send Shell command

                if (tn.WaitForChangedScreen())
                    Text = tn.VirtualScreen.Hardcopy().TrimEnd();

                System.Threading.Thread.Sleep(2000);
                tn.SendResponse("nvram reboot", true);	// send Shell command

                if (tn.WaitForChangedScreen())
                    Text = tn.VirtualScreen.Hardcopy().TrimEnd();

            } while (false);
            tn.Close();
        }
Exemple #3
0
 private void SocketTelnet(object state)
 {
     NSButtonsChange(false);
     rtbNU.Clear();
     int port = 0;
     if (int.TryParse(txtPort.Text, out port))
     {
         using (Terminal term = new Terminal(txtHostOrIP.Text, port, 3000, 0, 0))
         {
             string msg = string.Format("telnet {0}:{1} ", txtHostOrIP.Text, txtPort.Text);
             if (term.Connect())
             {
                 rtbNU.AppendText(msg + " Connected");
             }
             else
             {
                 rtbNU.AppendText(msg + " Disconnected");
             }
         }
     }
     else
     {
         MessageBox.Show("invalid Port");
     }
     NSButtonsChange(true);
 }