Created
May 18, 2024 20:19
-
-
Save Delnegend/fa622259110fbf719dea08cb7c511496 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from dataclasses import dataclass | |
import argparse | |
import os, binascii | |
@dataclass | |
class AccessPoint: | |
name: str | |
mac_addr: str | |
aps = [ | |
AccessPoint("Test 2.4", "11:22:33:44:55:66"), | |
AccessPoint("Test 5", "AA:BB:CC:EE:DD:FF"), | |
] | |
def random_hex(length: int): | |
return binascii.b2a_hex(os.urandom(length)) | |
def parse_arguments(): | |
"""argument parser""" | |
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter) | |
parser.add_argument( | |
'--format', | |
choices=['uci','config'], | |
default='config', | |
help='output format\n' | |
' uci: prints uci commands (default)\n' | |
' config: prints config file snippets') | |
return parser.parse_args() | |
if __name__ == '__main__': | |
ARGS = parse_arguments() | |
password = random_hex(16).decode() | |
mobility_domain = random_hex(2).decode() | |
output_prefix, output_seperator = "", "" | |
if 'uci' in ARGS.format: | |
output_prefix = 'uci set wireless.@wifi-iface[{}].' | |
output_seperator = '=' | |
elif 'config' in ARGS.format: | |
output_prefix = '\toption ' | |
output_seperator = ' ' | |
r0kh: list[str] = [] | |
r1kh: list[str] = [] | |
for ap in aps: | |
r0kh.append(f"{ap.mac_addr},{ap.mac_addr.replace(':', '')},{password}") | |
r1kh.append(f"{ap.mac_addr},{ap.mac_addr},{password}") | |
for ap in aps: | |
# prefix = output_prefix.format(ap.index - 1) | |
prefix = output_prefix | |
nasid = ap.mac_addr.replace(':', '') | |
print(f"Config for {ap.name}:\n") | |
print(f"{prefix}ieee80211r{output_seperator}'1'") | |
print(f"{prefix}ft_psk_generate_local{output_seperator}'0'") | |
print(f"{prefix}max_inactivity{output_seperator}'15'") | |
print(f"{prefix}dtim_period{output_seperator}'3'") | |
print(f"{prefix}ft_over_ds{output_seperator}'0'") | |
print(f"{prefix}reassociation_deadline{output_seperator}'20000'") | |
print(f"{prefix}ieee80211w{output_seperator}'2'") | |
print(f"{prefix}mobility_domain{output_seperator}'{mobility_domain}'") | |
print(f"{prefix}pmk_r1_push{output_seperator}'1'") | |
print(f"{prefix}nasid{output_seperator}'{nasid}'") | |
print(f"{prefix}r1_key_holder{output_seperator}'{nasid}'") | |
print(f"{prefix}macaddr{output_seperator}'{ap.mac_addr}'") | |
if 'uci' in ARGS.format: | |
print(f"{prefix}r0kh{output_seperator}'{','.join(r0kh)}'") | |
print(f"{prefix}r1kh{output_seperator}'{','.join(r1kh)}'") | |
elif 'config' in ARGS.format: | |
for r0kh_item in r0kh: | |
print(f"\tlist r0kh '{r0kh_item}'") | |
for r1kh_item in r1kh: | |
print(f"\tlist r1kh '{r1kh_item}'") | |
print() | |
if 'uci' in ARGS.format: | |
print(" 'uci commit wireless' to commit the changes") | |
print("'wifi reload' to reload the wifi config\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment