获取 ip地址
ifconfig eth0 | grep 'inet addr' | sed 's/^.*addr://' | sed 's/[[:space:]].*//'
获取 网关地址
route | grep default | sed 's/default[[:space:]]*//' | sed 's/[[:space:]].*$//'
wifi 连接脚本 connect_wifi.sh
用法举例: connect_wifi.sh ssid 123456
CFGFILE=/home/wpa_supplicant.conf
SSID=$1
PSK=$2
echo SSID=$SSID
echo PSK=$PSK
echo ctrl_interface=/var/run/wpa_supplicant > $CFGFILE
echo network={ >> $CFGFILE
echo ssid=\"$SSID\" >> $CFGFILE
echo scan_ssid=1 >> $CFGFILE
echo key_mgmt=WPA-PSK >> $CFGFILE
echo psk=\"$PSK\" >> $CFGFILE
echo } >> $CFGFILE
killall udhcpc
killall wpa_supplicant
wpa_supplicant -iwlan0 -c /home/wpa_supplicant.conf -B
udhcpc -i wlan0
sleep 3
echo "wifi ip:"
ifconfig wlan0 | grep 'inet addr' | sed 's/^.*addr://' | sed 's/[[:space:]].*//'
echo "wifi gw:"
route | grep default | grep wlan | sed 's/default[[:space:]]*//' | sed 's/[[:space:]].*$//'