janmohammadi / MikrotikDotNet

Mikrotik C# API - MikrotikDotNet is a lightweight and easy to use ADO.NET like library for Mikrotik Api with extensibility and performance in mind.
34 stars 13 forks source link

how remove pppoe active user? #10

Closed ghost closed 2 years ago

ghost commented 3 years ago

I need to lease this command: /ppp/active/remove using .id parameter. How can i do this?

janmohammadi commented 3 years ago

@mohsenghodrat

mohsenghodrat commented 3 years ago

Hi daniel what do you want to do? by this code /ppp/active/remove numbeers=id you can kill (kick) user for a couple of seconds, if you want to remove a user, at first you must find the user id then remove it user, by id: for find users and id :

using (var conn = new MKConnection("192.168.1.5", "admin", "123456", 8291)) { conn.Open(); var cmd = conn.CreateCommand("ppp secret print"); cmd.Parameters.Add("where", "name"); var result = cmd.ExecuteReader(); foreach (var line in result) { //get list of users and id in /ppp/secret var raw = MikrotikDotNet.ReponseParser.RowParser.Parse(line); //print user id Console.WriteLine(raw[".id"]); //Get user id //var id = raw[".id"].Substring(1); } } for remove user :

using (var conn = new MKConnection("192.168.1.5", "admin", "123456", 8291)) { conn.Open(); cmd = conn.CreateCommand("ppp secret remove"); cmd.Parameters.Add("numbers", id.toString()); cmd.ExecuteNonQuery(); }

simple code:

using (var conn = new MKConnection("192.168.1.5", "admin", "123456", 8291)) { conn.Open(); var cmd = conn.CreateCommand("ppp secret print"); cmd.Parameters.Add("where", "name"); var result = cmd.ExecuteReader(); foreach (var line in result) { //get list of users and id in /ppp/secret var raw = MikrotikDotNet.ReponseParser.RowParser.Parse(line); //Get user id var id = raw[".id"].Substring(1); //remove user by id cmd = conn.CreateCommand("ppp secret remove"); cmd.Parameters.Add("numbers", id.ToString()); cmd.ExecuteNonQuery(); } }

ghost commented 3 years ago

Thanks a lot!