scripts/python/ssid-valid-len.py

36 lines
1.0 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
2023-05-18 09:06:16 +02:00
"""
This script asks for a SSID name, counts it and tells whether it's of valid
length
2023-05-18 09:06:16 +02:00
"""
# Request input or assume "test" on empty.
2023-05-18 09:06:16 +02:00
givenssid = str(
input(
2023-10-10 09:16:58 +02:00
"Please enter the SSID you are thinking of (preferably 26 chars to fit _nomap): ",
2023-05-18 09:06:16 +02:00
)
2023-10-10 09:16:58 +02:00
or "test",
2023-05-18 09:06:16 +02:00
)
# Ensure it's UTF-8 and store the size. E.g. åäö are longer than oao
# TODO: make this a function too
givenssidlen = len(givenssid.encode("utf8"))
2023-05-18 09:06:16 +02:00
# Checking the SSID length is done twice, so thus a function
def checkssidlen(givenssidlen):
# 32 bytes should be the maximum SSID length
if givenssidlen <= 32:
print(givenssid, "is", givenssidlen, "long and thus valid length")
else:
print(givenssid, "is", givenssidlen, "to long, please select a different SSID")
2023-05-18 09:06:16 +02:00
# Checking the SSID without _nomap
checkssidlen(givenssidlen)
# TODO: make this a function too
givenssidlen = len(givenssid.encode("utf8"))
# Continuing with _nomap to ensure it also fits
givenssid = givenssid + "_nomap"
checkssidlen(givenssidlen)