Community discussions

 
netbus
newbie
Topic Author
Posts: 39
Joined: Mon Sep 04, 2017 12:42 pm

how to get .id via python

Sun Jun 09, 2019 5:00 pm

Hello,
I am trying to get an id via python and api:
api = connection.get_api()
list_address = api.get_resource('/ip/firewall/address-list/')
test = list_address.get(address="1.2.3.4")
print(test)
connection.disconnect()
The Output looks like this:
[{u'creation-time': u'jun/07/2019 16:23:33', u'list': u'port scanners', u'dynamic': u'true', u'disabled': u'false', u'timeout': u'1w5d27m59s', u'address': u'1.2.3.4', u'id': u'*62C'}]
But how can I get the ID only?
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5841
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: how to get .id via python

Mon Jun 10, 2019 11:52 am

To get only specific parameter via API use proplist, wiki has all the info you need:
https://wiki.mikrotik.com/wiki/Manual:A ... escription
And here is example:
https://wiki.mikrotik.com/wiki/Manual:API#OID
 
netbus
newbie
Topic Author
Posts: 39
Joined: Mon Sep 04, 2017 12:42 pm

Re: how to get .id via python

Mon Jun 10, 2019 12:22 pm

thanks for your reply but I not looking for OID but rather .id
test = api(cmd='/ip/firewall/address-list/print')
id = api(cmd='/=.proplist=.id')
brings:
librouteros.exceptions.MultiTrapError: no such command or directory (=.proplist=.id), no such command
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 1060
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: how to get .id via python

Mon Jun 10, 2019 2:10 pm

print gives names, find gives id.

In cli you can get id with this command
/ip firewall address-list find
The see the id
:put [/ip firewall address-list find]
 
How to use Splunk to monitor your MikroTik Router

MikroTik->Splunk
 
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5841
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: how to get .id via python

Mon Jun 10, 2019 2:44 pm

thanks for your reply but I not looking for OID but rather .id
test = api(cmd='/ip/firewall/address-list/print')
id = api(cmd='/=.proplist=.id')
brings:
librouteros.exceptions.MultiTrapError: no such command or directory (=.proplist=.id), no such command
Most likely you are doing message encoding wrong. You are trying to send =.proplist as a new separate command, not parameter for previous command.
Use our python reference example from our wiki:
https://wiki.mikrotik.com/wiki/Manual:A ... ple_client
 
netbus
newbie
Topic Author
Posts: 39
Joined: Mon Sep 04, 2017 12:42 pm

Re: how to get .id via python

Mon Jun 10, 2019 4:53 pm

I understand now:
/ip/firewall/address-list/getall
?address=0.0.0.0/8
=.proplist=.id

<<< /ip/firewall/address-list/getall
<<< ?address=0.0.0.0/8
<<< =.proplist=.id
<<< 
>>> !re
>>> =.id=*1
>>> 
>>> !done
>>> 

I am using librouteros or routeros-api but there I cann't find how to add this attributes

Who is online

Users browsing this forum: Google [Bot] and 4 guests