I have start working with Python API
using routeros_api
I want to change a nar rule according to it's name
I manage to do this
Code: Select all
connection = routeros_api.RouterOsApiPool('10.0.0.138', username='admin', password='password',plaintext_login=True)
api = connection.get_api()
NatRule = api.get_resource('/ip/firewall/nat')
print(NatRule.get(comment=RDP'))
Code: Select all
[{'id': '*12', 'chain': 'dstnat', 'action': 'dst-nat', 'to-addresses': '10.0.0.100', 'to-ports': '3389', 'protocol': 'tcp', 'dst-address': 192.168.5.20', 'in-interface': 'all-ppp', 'dst-port': '3389', 'log': 'false', 'log-prefix': '', 'bytes': '44', 'packets': '1', 'invalid': 'false', 'dynamic': 'false', 'disabled': 'true', 'comment': 'RDP'}]
Code: Select all
NatRule.set(id='*12',disabled='false')
in another router it would be another id
is there a faster way to get this data using the API?
Thanks ,