Пример #1
0
        public static bool suspendpppoeuser(string pppoeuser)
        {
            using (ITikConnection connection = ConnectionFactory.CreateConnection(TikConnectionType.Api)) // Use TikConnectionType.Api for mikrotikversion prior v6.45
            {
                connection.Open("10.19.10.1", "OrionAdmin", "Frank1e2015");


                var pppoeactive = connection.LoadList <PppActive>();
                foreach (PppActive pppa in pppoeactive)
                {
                    string ipaddress = "";
                    if (pppa.Name == pppoeuser)
                    {
                        ipaddress = pppa.Address;
                    }
                    if (ipaddress != "")
                    {
                        ITikCommand cmd = connection.CreateCommand("/ip/firewall/address-list/add",
                                                                   connection.CreateParameter("list", "unmssuspend"),
                                                                   connection.CreateParameter("address", ipaddress),
                                                                   connection.CreateParameter("comment", "suspend"));
                        cmd.ExecuteAsync(response =>
                        {
                            // Console.WriteLine("Row: " + response.GetResponseField("tx"));
                        });

                        cmd.Cancel();
                    }
                }

                connection.Close();
            }
            return(true);
        }
Пример #2
0
        //
        // Button Connect
        //
        private void btnConnect_MouseClick(object sender, MouseEventArgs e)
        {
            string action = btnConnect.Text;

            if (action == "Connect")
            {
                string host     = txtHost.Text;
                string user     = txtUser.Text;
                string password = txtPassword.Text;
                if (!host.IsNullOrWhiteSpace() && !user.IsNullOrWhiteSpace())
                {
                    try
                    {
                        connection.OnReadRow  += Connection_OnReadRow;
                        connection.OnWriteRow += Connection_OnWriteRow;
                        connection.Open(host, user, password);
                        lblStatus.Text      = "Connected";
                        lblStatus.ForeColor = System.Drawing.Color.Green;
                        tableOption.Visible = true;
                        btnSubmit.Enabled   = true;
                        txtCommand.ReadOnly = false;
                        btnConnect.Text     = "Disconnect";
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
                else
                {
                    MessageBox.Show("Please Enter Your Host and Password.");
                }
            }
            else if (action == "Disconnect")
            {
                connection.Close();
                btnConnect.Text     = "Connect";
                lblStatus.Text      = "Disconnect";
                lblStatus.ForeColor = Color.Crimson;
                rtxDisplay.Text     = "";
                tableOption.Visible = false;
                btnSubmit.Enabled   = false;
                txtCommand.ReadOnly = true;
            }
        }
Пример #3
0
 /// <summary>
 /// Close connections and free resources
 /// </summary>
 public void Dispose()
 {
     _connection.Close();
 }