LoginSignup
0
0

More than 3 years have passed since last update.

seleniumからfortigate(6.0)管理画面にログイン〜ログアウトしてみる

Posted at

やりたいこと

・webdriverで、ネットワーク機器の管理画面を操作してみたい。
・fortigateはRESTFULなインタフェースを持っているが、今回は考えない。

何が嬉しいの?

・fortigate管理画面にログインできなくなるような特異故障を監視できるかも。

用意するもの

・Forigate(今回はFortigate60D 6.0.x)
・ubuntu 20.04
・selenium+firefoxが動く環境(https://qiita.com/gaichi/items/1ece50111b50f8de6453)

下調べ(elementの調査方法)

・Firefoxにselenium IDE pluginを導入し、recordで記録した結果を見る。
・HTMLのソースから探し出す。
recordの記録ですが、操作をうまく拾えず、同じ操作でも異なる結果が出ることがあります。HTMLはなんとなく理解していますが、cssは全然理解していないので結構適当に探しました。

ソース

#!/bin/python3

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
import time

USERNAME='admin'
PASSWORD='password'
LOGINURL='https://192.168.1.99/login'

# ブラウザ起動
options = Options()
options.binary_location = '/usr/bin/firefox'
#options.add_argument('-headless')
driver = webdriver.Firefox(options=options)

# Fortigateログイン画面の取得
driver.get(LOGINURL)

# ID,Passwordの入力
time.sleep(1)
driver.find_element_by_id('username').send_keys(USERNAME)
time.sleep(1)

driver.find_element_by_id('secretkey').send_keys(PASSWORD)
time.sleep(1)

driver.find_element_by_name('login_button').click()
time.sleep(5)
# ↑管理画面の表示は時間がかかるので、長めに待つ。

# Adminメニューをクリック
driver.find_element_by_class_name('admin-avatar').click();
time.sleep(2)

# ログアウトをクリック
driver.find_element_by_class_name('fa-sign-out').click();
time.sleep(10)

# ブラウザーを終了
driver.quit()
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0