Esta é uma amostra ./script
incluindo o comando wpa_passphrase
para configurar O SSID
e o password
:
#!/bin/bash
if iwgetid; then
wpa_cli terminate
ip addr flush wlan0
ip link set dev wlan0 down
rm -r /var/run/wpa_supplicant > /dev/null
ip link set dev wlan0 up
fi
wpa_supplicant -B -i wlan0 -c<(wpa_passphrase "$1" "$2") > /dev/null 2>&1
dhclient wlan0
service ntp restart
exit
Uso:
sudo ./script "My SSID" "My-Password"
Atualizar
Se o wpa_supplicant
for bem-sucedido e autenticado com o ssid
e pass
, você receberá WPA: Key negotiation completed
no arquivo de log.
A opção -f
adicionada ao comando wpa_supplicant
para fornecer um arquivo log
.
Você pode verificar o status de saída de grep
antes de executar o comando dhclient
.
#!/bin/bash
if iwgetid; then
wpa_cli terminate
ip addr flush wlan0
ip link set dev wlan0 down
rm -r /var/run/wpa_supplicant > /dev/null
ip link set dev wlan0 up
fi
# A minimal wpa_supplicant.conf configuration file.
echo -e "\nctrl_interface=/run/wpa_supplicant \nupdate_config=1\n" > /etc/wpa_supplicant/wpa_supplicant.conf
# A prompt for SSID and WPA passphrase. The -f option to get a log file.
# sleep command will be useful because the authentication will take a few
# second before executing grep.
echo "" > logfile
wpa_supplicant -B -i wlan0 -c<(wpa_passphrase "$1" "$2") -f logfile
sleep 10
grep -c "WPA: Key negotiation completed" logfile
if [ $? -eq 0 ]
then
echo "Key negotiation completed successfully"
timeout 15 dhclient wlan0
exit 0
else
echo "Authentication failed"
fi
exit 1
Uso:
sudo ./script "My SSID" "My-Password"