Last active
December 5, 2022 02:58
-
-
Save viz-prakash/639e539763736ea2ff91c2a2b24bbd8a to your computer and use it in GitHub Desktop.
Connects to a wifi ssid available from command prompt on Raspberry pi
This file contains 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 | |
# Connects to a wifi ssid available from command prompt on Raspberry pi | |
# run it with sudo | |
# you might have to kill wpa_supplicant and dhclient | |
# sudo killall wpa_supplicant | |
# sudo killall dhclient | |
apt -y install wireless-tools wpasupplicant | |
iw dev wlan0 scan | grep SSID | |
# another command to get list of available ssid | |
# iwlist scan | grep -i ssid | |
SSID="your-sssid" | |
WPA_CONFIG="./custom_wpa_supplicant.conf" | |
echo "This script connects to $SSID" | |
echo "Enter the password for $SSID" | |
wpa_passphrase $SSID > $WPA_CONFIG | |
echo "$WPA_CONFIG file generated" | |
echo "Connecting to $SSID" | |
#wpa_supplicant -D wext -i wlan0 -c $WPA_CONFIG -B | |
# some place like stackexchange suggest adding -D wext, but it doesn't work with raspberry pi. | |
wpa_supplicant -i wlan0 -c $WPA_CONFIG -B & | |
echo "Obtaining IP address using DHCP" | |
sleep 10 | |
dhclient wlan0 & |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment