omidh
September 13, 2010, 6:36am
1
Dear All,
I found following thread for killing users using their username
http://forum.mikrotik.com/viewtopic.php?f=2&t=20542&start=0
The syntax is as follow:
ppp act rem [find name=user1]
for example: ppp active remove [find name=testuser]
I use Mikrotik API in VC++
mikrotik.Send(“/ppp/active/remove [find name=” + szUsername + “]”);
mikrotik.Send(“.tag=sss”, true);
The code in Mikrotik terminal works fine but nothing happend in VC++ code.
Any suggestion?
mrz
September 13, 2010, 6:40am
2
API is not a scripting language and, there is no command “find”. You have to use queries.
http://wiki.mikrotik.com/wiki/Manual:API#Queries
omidh
September 13, 2010, 12:14pm
3
Dear support,
Thanks for your reply. I didn’t understand that is it possible to kill users using API or not?
If it’s possible, how?
Best regards,
omidh
mrz
September 13, 2010, 12:23pm
4
Yes, it is possible
/ppp/active/remove
?name=testuser
=.tag=sss
omidh
September 13, 2010, 12:49pm
5
Sorry for my stupid question. I have wrote following code using VC#, but nothing happens. Would you please help:
MK mikrotik = new MK(NASIP);
if (!mikrotik.Login(szUsername, szPassword))
{
Console.WriteLine("Could not log in");
mikrotik.Close();
return;
}
mikrotik.Send("/ppp/active/remove");
mikrotik.Send("?name=testuser");
mikrotik.Send(".tag=sss", true);
Chupaka
September 13, 2010, 4:17pm
6
I think, it should be like this:
/ppp/active/remove
=.id=testuser
Chupaka
September 14, 2010, 12:09am
8
well, it works at least with v3.28:
first,
/ppp/active/print
?name=testuser
=.proplist=.id
and then execute this with the result from previous command:
/ppp/active/remove
=.id=*VALUE*
omidh
September 14, 2010, 6:03am
9
I found user id after printing all online users, then use following:
mikrotik.Send("/ppp/active/remove");
mikrotik.Send("=.id=CBDCD3");
mikrotik.Send("=.tag=sss", true);
I also test =.id=*CBDCD3, =.id=CBDCD3 , =.id=CBDCD3, but nothing happened.
Any suggestion???
Chupaka
September 14, 2010, 6:21am
10
recheck. as I said, http://forum.mikrotik.com/t/using-api-in-mikrotik/40715/8 works for me
p.s. if user logs in again, he has new .id
omidh
September 14, 2010, 5:54pm
11
Thanks for your reply, If you have any code, would you please give me it?
I wrote following code:
mikrotik.Send("/ppp/active/print");
mikrotik.Send("?name=testuser");
mikrotik.Send("=.proplist=.id");
mikrotik.Send("/ppp/active/remove");
mikrotik.Send("=.id=*CC7334");
mikrotik.Send("=.tag=sss", true);
About following line
mikrotik.Send(“=.id=*CC7334”);
Does it correct? =.id=*CC7334? or it needs another * after CC7334?
Thanks
Chupaka
September 14, 2010, 8:22pm
12
“/ppp/active/print” is used to get exact value of .id
after that you should read the result, and use the value in “/ppp/active/remove” command
don’t think about the number of asterisks - use the value you received from first command
omidh
September 17, 2010, 6:41am
13
I have changed the code to the following and it’s now working well
mikrotik.Send("/ppp/active/print");
mikrotik.Send("?name=" + szUsername);
mikrotik.Send("=.proplist=.id", true);
List<string> s = mikrotik.Read();
// ...
// Some code for retrieving ID from s
// szID = ....
mikrotik.Send("/ppp/active/remove");
mikrotik.Send("=.id=" + szID, true);
Thanks.