标签:wi-fi 路由器 脚本 ubuntu wpa_supplicant
主要是使用命令行下,控制wifi接口连接无线路由器,写了一个简单的脚本,仅供参考!
leekwen@print:~$ cat wifi-link.sh #!/bin/sh # # author leekwen # read -p "Enter Wifi SSID Name: " ssid echo "\n \033[32m The WIFI SSID is $ssid. \033[0m \n" read -p "Enter the password of SSID:" password echo "\n \033[32m The Password is $password \033[0m\n" wpa_passphrase $ssid $password > /etc/wpa_supplicant.conf wpa=`ps -ef |grep wpa_supplicant|grep -v "grep" |wc -l` dhc=`ps -ef |grep "dhclient wlan0" |grep -v "grep" |wc -l` #echo "dhclient is $dhc " pid=`pgrep wpa_supplicant` cid=`ps -ef |grep "dhclient wlan0" |grep -v "grep" |awk '{print $2}'` #echo $cid if [ $wpa -eq 0 ]; then echo " process is none " wpa_supplicant -B -Dwext -iwlan0 -c /etc/wpa_supplicant.conf & if [ $cid -eq 0 ]; then dhclient wlan0 & else kill $cid sleep 1; dhclient wlan0 & fi else echo "\n \033[31m The process is exists...... \033[0m \n" #echo $pid kill $pid & sleep 1 echo "\n \033[31m The interface will restart...... \033[0m \n" wpa_supplicant -B -Dwext -iwlan0 -c /etc/wpa_supplicant.conf & if [ $cid -eq 0 ]; then dhclient wlan0 & else kill $cid sleep 1; dhclient wlan0 & fi fi
根据提示输入wifi的SSID名称及密码后,WIFI接口会自动重启,并从路由上动态获取IP地址。
如果wifi的接口名非wlan0,请自行修改此脚本,以方便自己能够正常使用。
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:wi-fi 路由器 脚本 ubuntu wpa_supplicant
原文地址:http://blog.csdn.net/leekwen/article/details/48023321