2018/11/13

fortiOS 5.2的REST有問題 不要用


最近有個朋友問我有沒有用過fortiget rest的功能 5.2之後提供
其實之前就有再找
只是後來程式都直接用 ssh或telnet去下指令
既然有人問了
就再來找找

一閞始找到的這二個資料
可以查 可以刪 但不能新增 也不能update
所以不要再浪費時間了


直到後來找到這個 完全沒問題啊 而且也不用自己去寫jason格式 而且反應速度相當快

https://github.com/DavidChayla/FortigateApi/blob/master/README.md

記錄一下用法

首先要下載回來後要先 import

import sys
sys.path.append('PATH TO FortigateApi.py')

再來依照文件說明

import FortigateApi

fg = FortigateApi.Fortigate('10.20.30.40', 'root', 'admin', 'mypasswd')

fg.AddFwAddress('srv-A','10.1.1.1/32')

200

fg.GetFwAddress('srv-A')

u'{\n "http_method":"GET",\n "results":[\n {\n "name":"srv-A",\n "q_origin_key":"srv-A",\n "uuid":"2103d064-d520-51e6-de84-16e9ab03b8ae",\n "subnet":"10.1.1.1 255.255.255.255",\n "type":"ipmask",\n "start-ip":"10.1.1.1",\n "end-ip":"255.255.255.255",\n "fqdn":"",\n "country":"",\n "url":"",\n "cache-ttl":0,\n "wildcard":"10.1.1.1 255.255.255.255",\n "comment":"",\n "visibility":"enable",\n "associated-interface":"",\n "color":0,\n "tags":[\n ]\n }\n ],\n "vdom":"dc2",\n "path":"firewall",\n "name":"address",\n "mkey":"srv-A",\n "status":"success",\n "http_status":200,\n "serial":"FWF90D3Z13003141",\n "version":"v5.2.9",\n "build":736\n}'

fg.SetFwAddress('srv-A','10.2.2.2/32')

200

fg.DelFwAddress('srv-A')

200


沒有留言: