Closed zephyr2k7 closed 2 years ago
Example how to get all policies with destination address == "192.168.1.2/32"
from pprint import pprint
from fortigate_api import FortigateAPI
fgt = FortigateAPI(host="host", username="username", password="password")
fgt.login()
policies = []
addresses = fgt.address.get(filter="subnet==192.168.1.2 255.255.255.255")
for policy in fgt.policy.get():
dstaddr = [d["name"] for d in policy["dstaddr"]]
for address in addresses:
if address["name"] in dstaddr:
policies.append(policy)
pprint(policies)
thankyou very much
Since version 0.2.1 you can use extended filter to make it easier to find rules by source or destination addresses.
from pprint import pprint
from fortigate_api import FortigateAPI
fgt = FortigateAPI(host="host", username="username", password="password")
fgt.login()
policies = fgt.policy.get(efilter="srcaddr<=192.168.0/24")
pprint(policies)
Hi, Regarding the policy filters how can I try to get all policies filtered by destination address? For example to extract all policies that allora traffic to a specific il say 192.168.1.2?
Thanks in advance for your help