-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunlock-wifi.sh
42 lines (34 loc) · 1.26 KB
/
unlock-wifi.sh
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
38
39
40
41
42
#!/bin/bash
# Log message function
log_message() {
local message="$1"
echo "$(date '+%Y-%m-%d %H:%M:%S') - $message" >> /var/log/lockssid.log
}
# Get the current SSID
SSID=$(nmcli -t -f ACTIVE,SSID dev wifi | grep '^yes:' | cut -d':' -f2)
if [ -z "$SSID" ]; then
log_message "No active Wi-Fi connection found. Exiting."
exit 1
fi
# Get the wifi card's device name
DEVICE_NAME=$(iw dev | grep Interface | awk '{print $2}')
if [ -z "$DEVICE_NAME" ]; then
log_message "No wireless device found. Exiting."
exit 1
fi
# Unlocking logic with additional logging
log_message "Unlocking Wi-Fi for SSID: $SSID"
nmcli con mod "$SSID" 802-11-wireless.bssid ''
log_message "Cleared BSSID lock for SSID: $SSID"
# Turn on power saving mode using nmcli
nmcli con mod "$SSID" 802-11-wireless.powersave 3
log_message "Turned on power saving mode for SSID: $SSID"
# Disconnect and reconnect if the device is active
if nmcli device status | grep -q "$DEVICE_NAME.*connected"; then
log_message "Disconnecting and reconnecting device: $DEVICE_NAME"
nmcli device disconnect "$DEVICE_NAME"
nmcli device connect "$DEVICE_NAME"
log_message "Reconnected device: $DEVICE_NAME"
else
log_message "Device $DEVICE_NAME is not active. Skipping disconnect and reconnect."
fi