Help us understand the problem. What is going on with this article?

FortiGateのアプリケーションコントロールIDを取得する

はじめに

FortiGateのアプリケーションコントロールIDはfortiguard.comにて公開されてますが、一覧では表示されません。。。
フローコレクタに情報を読み込ませる時など、csvで一覧が欲しいと思った方は少なからずいるはず。

本体から取得する

下記のコマンドを利用してCLIから一覧を取得できます。

config application list
edit default
config entries
edit 1

# set application ?

?を入力すると出力されるわけですが、機器によって対応しているアプリケーションが異なるので、できればfortiguard.comから全てのデータを取得したい。

自作ツール作りました。

pythonで自作ツールを作りました。

pip install beautifulsoup4 lxml requests
import requests
import csv
import re
import time
from bs4 import BeautifulSoup

s = requests.Session()

url = 'https://fortiguard.com/appcontrol'
get_url_info = s.get(url)
bs4Obj = BeautifulSoup(get_url_info.text, 'lxml')
result = bs4Obj.find('div', class_='sidebar-content')
appids = int(re.findall('[0-9]+', result.find('a').get_text().replace(',', ''))[0])
perPage = int(len(bs4Obj.find_all('div', class_='title')))
pages = int(appids / perPage) + 1

i = 1
datas = []
url_base = 'https://fortiguard.com/appcontrol?deepapp=&page='

while pages + 1 > i:
    print('page:', i, '/', pages)
    url = url_base + str(i)
    try:
        get_url_info = s.get(url)
        bs4Obj = BeautifulSoup(get_url_info.text, 'lxml')
        app_list = bs4Obj.find_all('div', class_='title')
        if len(app_list) == 0:
            continue
    except Exception as e:
        print(e)
        time.sleep(1)
        continue
    j = 0
    while True:
        try:
            app_name = str(app_list[j].find('a').get_text())
            app_num = int(re.findall('[0-9]+', app_list[j].find('a').get('href'))[0])
            data = [app_num, app_name]
            datas.append(data)
            j += 1
        except:
            break
    i += 1

print('result:', len(datas), '/', appids)

with open('appid.csv', 'w') as file:
    writer = csv.writer(file, lineterminator='\n')
    writer.writerows(sorted(datas))

Githubに同じコードをアップしてます。
https://github.com/Connie-Wild/FortiOS_AppControlID
それでは!

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした