API_Interfaces
I created API calls to all of the physical interfaces on my 61F.
Main.py
import API_Interfaces_a
import API_Interfaces_b
import API_Interfaces_internal1
import API_Interfaces_internal2
import API_Interfaces_internal3
import API_Interfaces_internal4
import API_Interfaces_internal5
import API_Interfaces_DMZ
if __name__ == '__main__':
# noinspection PyStatementEffect
API_Interfaces_a
# noinspection PyStatementEffect
API_Interfaces_b
# noinspection PyStatementEffect
API_Interfaces_internal1
# noinspection PyStatementEffect
API_Interfaces_internal2
# noinspection PyStatementEffect
API_Interfaces_internal3
# noinspection PyStatementEffect
API_Interfaces_internal4
# noinspection PyStatementEffect
API_Interfaces_internal5
# noinspection PyStatementEffect
API_Interfaces_DMZ
config.py
api_url = "https://xxxxxxxxxxxxxxxxxxxx/api/v2/cmdb/system/interface"
api_url_port1 = "https://xxxxxxxxxxxxxxxxxxxx/api/v2/cmdb/system/interface/internal1"
api_url_port2 = "https://xxxxxxxxxxxxxxxxxxxx/api/v2/cmdb/system/interface/internal2"
api_url_port3 = "https://xxxxxxxxxxxxxxxxxxxx3/api/v2/cmdb/system/interface/internal3"
api_url_port4 = "https://xxxxxxxxxxxxxxxxxxxx/api/v2/cmdb/system/interface/internal4"
api_url_port5 = "https://xxxxxxxxxxxxxxxxxxxx/api/v2/cmdb/system/interface/internal5"
api_url_porta = "https://xxxxxxxxxxxxxxxxxxxx/api/v2/cmdb/system/interface/a"
api_url_portb = "https://xxxxxxxxxxxxxxxxxxxx/api/v2/cmdb/system/interface/b"
api_url_dmz = "https://xxxxxxxxxxxxxxxxxxxx/api/v2/cmdb/system/interface/dmz"
ACCESS_TOKEN = 'xxxxxxxxxxxxxxxxxxxx'
API_Interfaces_a.py
from pprint import pprint
import requests
import config
url = config.api_url_porta
key = { 'Authorization': f'Bearer {config.ACCESS_TOKEN}' }
response = requests.request("GET", url, headers=key )
# 200 status code
pprint(response.status_code)
file_path = f"C:/Users/netadmin/Documents/Interfaces/Interfaces_a.conf"
with open(file_path, 'wb') as f:
for line in response:
f.write(line)
# curl -X GET "https://<FortiGate_IP>/api/v2/cmdb/system/interface?access_token=<YOUR_API_TOKEN>"
# curl -X GET "https://<FortiGate_IP>/api/v2/cmdb/system/interface/port1?access_token=<YOUR_API_TOKEN>"
API_Interfaces_b.py
from pprint import pprint
import requests
import config
url = config.api_url_portb
key = { 'Authorization': f'Bearer {config.ACCESS_TOKEN}' }
response = requests.request("GET", url, headers=key )
# 200 status code
pprint(response.status_code)
file_path = f"C:/Users/netadmin/Documents/Interfaces/Interfaces_b.conf"
with open(file_path, 'wb') as f:
for line in response:
f.write(line)
# curl -X GET "https://<FortiGate_IP>/api/v2/cmdb/system/interface?access_token=<YOUR_API_TOKEN>"
# curl -X GET "https://<FortiGate_IP>/api/v2/cmdb/system/interface/port1?access_token=<YOUR_API_TOKEN>"
API_Interface_internal1.py
from pprint import pprint
import requests
import config
url = config.api_url_port1
key = { 'Authorization': f'Bearer {config.ACCESS_TOKEN}' }
response = requests.request("GET", url, headers=key )
# 200 status code
pprint(response.status_code)
file_path = f"C:/Users/netadmin/Documents/Interfaces/Interfaces_internal1.conf"
with open(file_path, 'wb') as f:
for line in response:
f.write(line)
# curl -X GET "https://<FortiGate_IP>/api/v2/cmdb/system/interface?access_token=<YOUR_API_TOKEN>"
# curl -X GET "https://<FortiGate_IP>/api/v2/cmdb/system/interface/port1?access_token=<YOUR_API_TOKEN>"
API_Interfaces_internal2.py
from pprint import pprint
import requests
import config
url = config.api_url_port2
key = { 'Authorization': f'Bearer {config.ACCESS_TOKEN}' }
response = requests.request("GET", url, headers=key )
# 200 status code
pprint(response.status_code)
file_path = f"C:/Users/netadmin/Documents/Interfaces/Interfaces_internal2.conf"
with open(file_path, 'wb') as f:
for line in response:
f.write(line)
# curl -X GET "https://<FortiGate_IP>/api/v2/cmdb/system/interface?access_token=<YOUR_API_TOKEN>"
# curl -X GET "https://<FortiGate_IP>/api/v2/cmdb/system/interface/port1?access_token=<YOUR_API_TOKEN>"
API_Interfaces_internal3.py
from pprint import pprint
import requests
import config
url = config.api_url_port3
key = { 'Authorization': f'Bearer {config.ACCESS_TOKEN}' }
response = requests.request("GET", url, headers=key )
# 200 status code
pprint(response.status_code)
file_path = f"C:/Users/netadmin/Documents/Interfaces/Interfaces_internal3.conf"
with open(file_path, 'wb') as f:
for line in response:
f.write(line)
# curl -X GET "https://<FortiGate_IP>/api/v2/cmdb/system/interface?access_token=<YOUR_API_TOKEN>"
# curl -X GET "https://<FortiGate_IP>/api/v2/cmdb/system/interface/port1?access_token=<YOUR_API_TOKEN>"
API_Interfaces_internal4.py
from pprint import pprint
import requests
import config
url = config.api_url_port4
key = { 'Authorization': f'Bearer {config.ACCESS_TOKEN}' }
response = requests.request("GET", url, headers=key )
# 200 status code
pprint(response.status_code)
file_path = f"C:/Users/netadmin/Documents/Interfaces/Interfaces_internal4.conf"
with open(file_path, 'wb') as f:
for line in response:
f.write(line)
# curl -X GET "https://<FortiGate_IP>/api/v2/cmdb/system/interface?access_token=<YOUR_API_TOKEN>"
# curl -X GET "https://<FortiGate_IP>/api/v2/cmdb/system/interface/port1?access_token=<YOUR_API_TOKEN>"
API_Interfaces_internal5.py
from pprint import pprint
import requests
import config
url = config.api_url_port5
key = { 'Authorization': f'Bearer {config.ACCESS_TOKEN}' }
response = requests.request("GET", url, headers=key )
# 200 status code
pprint(response.status_code)
file_path = f"C:/Users/netadmin/Documents/Interfaces/Interfaces_internal5.conf"
with open(file_path, 'wb') as f:
for line in response:
f.write(line)
# curl -X GET "https://<FortiGate_IP>/api/v2/cmdb/system/interface?access_token=<YOUR_API_TOKEN>"
# curl -X GET "https://<FortiGate_IP>/api/v2/cmdb/system/interface/port1?access_token=<YOUR_API_TOKEN>"
API_Interfaces_DMZ
from pprint import pprint
import requests
import config
url = config.api_url_dmz
key = { 'Authorization': f'Bearer {config.ACCESS_TOKEN}' }
response = requests.request("GET", url, headers=key )
# 200 status code
pprint(response.status_code)
file_path = f"C:/Users/netadmin/Documents/Interfaces/Interfaces_DMZ.conf"
with open(file_path, 'wb') as f:
for line in response:
f.write(line)
# curl -X GET "https://<FortiGate_IP>/api/v2/cmdb/system/interface?access_token=<YOUR_API_TOKEN>"
# curl -X GET "https://<FortiGate_IP>/api/v2/cmdb/system/interface/port1?access_token=<YOUR_API_TOKEN>"