Before logging in to the web page to register users on the AC controller, the number of users felt that it took too long, pondered the user MAC and other information into the excel sheet, and used python to generate command line scripts, so that one-click import is much more convenient, self-use is still feasible, and you can modify it according to your actual situation.
import osThe script file written by the individual is for reference, and each person's needs may be different, so you can customize and modify it.import pandas
Gets the absolute path of the current file.
current_file_path = os.path.abspath('.')
Obtain the file path of the MAC address table of the user.
mac_file_path = os.path.join(current_file_path, 'MAC address. xlsx')
Obtain the path to the ac configuration script file.
ac_script_file_path = os.path.join(current_file_path, 'ac.txt')
Open the AC configuration script file.
ac_script_file = open(ac_script_file_path, 'w', encoding='utf-8')
Read the user MAC address table file.
df = pandas.read_excel(mac_file_path, header=none)
Traverse through each row in the user's MAC address table file, including MAC address, authorization VLAN, and description
for i, j, k in df.values[:,0:3]:
Write the AC configuration script to the AC configuration script.
ac_script_file.write('local-user %s class network' % i)
ac_script_file.write('password **s' % i)
ac_script_file.write('service-type lan-access')
ac_script_file.write('authorization-attribute vlan %s' % j)
ac_script_file.write('authorization-attribute user-role network-operator')
ac_script_file.write('description %s' % k)
Close the AC configuration script file.
ac_script_file.close()
The first column contains the lowercase non-connector MAC address of the device to be registered, the second column writes the authorized VLAN, that is, the VLAN used by the user, and the third column is the comment of each user.
local-user mac1 class networkpassword **mac1
service-type lan-access
authorization-attribute vlan 10
authorization-attribute user-role network-operator
description 1
local-user mac2 class network
password **mac2
service-type lan-access
authorization-attribute vlan 10
authorization-attribute user-role network-operator
description 2
local-user mac3 class network
password **mac3
service-type lan-access
authorization-attribute vlan 10
authorization-attribute user-role network-operator
description 3