-
Notifications
You must be signed in to change notification settings - Fork 0
/
wlanpw.py
36 lines (28 loc) · 941 Bytes
/
wlanpw.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import re
import sys
from argparse import ArgumentParser
from pathlib import Path
from subprocess import check_output
def set_ap_pw(pw):
if len(pw) < 8:
raise ValueError('Password is too short')
config = Path('/etc/hostapd/hostapd.conf')
new_settings = re.sub(r'wpa_passphrase=.+', f'wpa_passphrase={pw}', config.read_text())
config.write_text(new_settings)
def reset():
set_ap_pw('12345678')
def set(pw):
set_ap_pw(pw)
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('--reset', action='store_true', help='Passwort zurücksetzen')
parser.add_argument('--set', help='Passwort setzen')
args = parser.parse_args()
if args.reset:
reset()
elif args.set:
try:
set(args.set)
except ValueError:
print('Passwort ist zu kurz. Mindestens 8 Zeichen sind erforderlich.', file=sys.stderr)
sys.exit(1)