[PYTHON] Log in to the fortigate (6.0) management screen from selenium-try to log out

Thing you want to do

-I want to operate the management screen of network devices with webdriver. -Fortigate has a RESTFUL interface, but I don't think about it this time.

What are you happy about

-It may be possible to monitor a peculiar failure that makes it impossible to log in to the fortigate management screen.

What to prepare

・ Fortigate (Fortigate-60D 6.0.x this time) ・ Ubuntu 20.04 ・ Environment where selenium + firefox works (https://qiita.com/gaichi/items/1ece50111b50f8de6453)

Preliminary survey (element survey method)

-Install the selenium IDE plugin in Firefox and see the results recorded by record. -Search from the HTML source. Although it is a record of record, the operation may not be picked up well and different results may be obtained even with the same operation. I understand HTML somehow, but I don't understand css at all, so I searched for it quite appropriately.

Source

#!/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'

#Launch browser
options = Options()
options.binary_location = '/usr/bin/firefox'
#options.add_argument('-headless')
driver = webdriver.Firefox(options=options)

#Get Fortigate login screen
driver.get(LOGINURL)

# ID,Enter 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)
#↑ It takes time to display the management screen, so wait for a long time.

#Click the Admin menu
driver.find_element_by_class_name('admin-avatar').click();
time.sleep(2)

#Click Log Out
driver.find_element_by_class_name('fa-sign-out').click();
time.sleep(10)

#Exit browser
driver.quit()

Recommended Posts

Log in to the fortigate (6.0) management screen from selenium-try to log out
How to log in automatically like 1Password from the CLI
DJango Memo: From the beginning (more edits to the management screen)
Log in to the remote server with SSH
Use pygogo to get the log in json.
Send log data from the server to Splunk Cloud
I can't log in to the admin page with Django3
How to take a screenshot of the Chrome screen (prevent it from cutting off in the middle)
Automatically acquire the operation log in the terminal when logging in to Linux
DJango memo: From the beginning (using the management screen) my addictive point
I tried to cut out a still image from the video
Change the active version in Pyenv from anaconda to plain Python
Programming to fight in the world ~ 5-1
Programming to fight in the world ~ 5-5,5-6
Programming to fight in the world 5-3
Programming to fight in the world-Chapter 4
In the python command python points to python3.8
Cython to try in the shortest
How to log in to Docker + NGINX
Programming to fight in the world ~ 5-2
[Completed version] Try to find out the number of residents in the town from the address list with Python
Throw GQL with a numeric ID from the App Engine management screen
How to check local GAE from iPhone browser in the same LAN
DJango memo: From the beginning (editing the management screen) There is a mystery
For the first time in Numpy, I will update it from time to time
Implemented in Dataflow to copy the hierarchy from Google Drive to Google Cloud Storage
Is it possible to extract the person's profile information from the chat log?
I tried to predict the number of people infected with coronavirus in consideration of the effect of refraining from going out
Cut out A4 print in the image
Log in to Slack using requests in Python
In Jupyter, add IPerl to the kernel.
How to operate Linux from the console
Various comments to write in the program
Password management technology in the GitHub era
How to access the Datastore from the outside
Convert from Markdown to HTML in Python
Use dHash to locate on the course from a scene in a racing game
Use PIL in Python to extract only the data you want from Exif
The first step to log analysis (how to format and put log data in Pandas)