-
Notifications
You must be signed in to change notification settings - Fork 0
/
wpa_passphrase.py
38 lines (31 loc) · 939 Bytes
/
wpa_passphrase.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
36
37
import sys
from argparse import ArgumentParser
from binascii import hexlify
from pathlib import Path
from hashlib import pbkdf2_hmac
CONFIG = """
country=de
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={{
ssid="{ssid}"
psk={psk}
# psk="{password}"
# proto=RSN
# key_mgmt=WPA-PSK
# pairwise=CCMP
# group=CCMP
}}
""".lstrip()
def gen_psk(ssid, password):
password, ssid = map(str.encode, (password.replace(' ', ''), ssid))
hash = pbkdf2_hmac('sha1', password, ssid, 4096, 32)
return hexlify(hash).decode()
def set_network(ssid, password):
if len(password) < 8:
raise ValueError('Passwort ist zu kurz. Mindestens 8 Zeichen.')
psk = gen_psk(ssid, password)
wpa_supplicant = Path('/etc/wpa_supplicant/wpa_supplicant.conf')
wpa_supplicant.write_text(
CONFIG.format(ssid=ssid, psk=psk, password=password)
)