Created
January 2, 2024 18:36
-
-
Save jigpu/bb84811dd0a300fc784225285e3f12b7 to your computer and use it in GitHub Desktop.
Set the SSID / password on C4000BG DSL modems
This file contains hidden or 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
#!/bin/bash | |
# Set the SSID / password on C4000BG DSL modems | |
# | |
# WARNING: This script does no sanity checking! It does not check | |
# that the SSID is available, or that it is even well-formed (i.e. | |
# 32 octets or less in length). Be careful! | |
set -e | |
COOKIE_FILE=cookies.txt | |
trap "rm \"${COOKIE_FILE}\"" EXIT | |
CURL_OPTS="--insecure --fail-with-body --connect-timeout 5 --cookie-jar \"${COOKIE_FILE}\" --cookie \"${COOKIE_FILE}\"" | |
function urlencode { | |
python -c "import urllib.parse; print(urllib.parse.quote_plus('$*'))" | |
} | |
function prompt { | |
echo -n "${1}" | |
read ${2} | |
} | |
function login { | |
prompt "LOGIN Username: " LOGIN_USERNAME | |
prompt "LOGIN Password: " LOGIN_PASSWORD | |
ESC_LOGIN_USERNAME=$(urlencode "${LOGIN_USERNAME}") | |
ESC_LOGIN_PASSWORD=$(urlencode "${LOGIN_PASSWORD}") | |
POST_DATA="username=${ESC_LOGIN_USERNAME}&password=${ESC_LOGIN_PASSWORD}" | |
echo "Logging in..." | |
curl ${CURL_OPTS} \ | |
--data "${POST_DATA}" \ | |
"https://${ADDRESS}/cgi/cgi_action" | |
} | |
function set_wifi_params { | |
prompt "Wifi SSID: " WIFI_SSID | |
prompt "Wifi Password: " WIFI_PASSWORD | |
ESC_WIFI_SSID=$(urlencode "${WIFI_SSID}") | |
ESC_WIFI_PASSWORD=$(urlencode "${WIFI_PASSWORD}") | |
POST_DATA="Object=Device.WiFi.SSID.1&Operation=Modify&SSID=${ESC_WIFI_SSID}&Object=Device.WiFi.AccessPoint.1.Security&Operation=Modify&ModeEnabled=WPA2-Personal&KeyPassphrase=${ESC_WIFI_PASSWORD}&Object=Device.WiFi.AccessPoint.1&Operation=Modify&SSIDAdvertisementEnabled=true&Object=Device.WiFi.SSID.2&Operation=Modify&SSID=${ESC_WIFI_SSID}&Object=Device.WiFi.AccessPoint.2.Security&Operation=Modify&ModeEnabled=WPA2-Personal&KeyPassphrase=${ESC_WIFI_PASSWORD}&Object=Device.WiFi.AccessPoint.2&Operation=Modify&SSIDAdvertisementEnabled=true" | |
echo "Setting Wifi parameters..." | |
curl ${CURL_OPTS} \ | |
--header "X-Requested-With: XMLHttpRequest" \ | |
--data "${POST_DATA}" \ | |
"https://${ADDRESS}/cgi/cgi_set" | |
} | |
prompt "Router address: " ADDRESS | |
login | |
set_wifi_params |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment