此方式 可以通过串口来操作
1.进入wpa_cli后,命令如下:
# wpa_cli
# scan
# scan_results
;会显示搜索到的wifi信号列表,假设你的wifi ssid是wireless0
# add_net 会打印一个net编号,如果打印0
0
# set_network 0 ssid "wireless0" //wifi名称
# set_network 0 psk "123456" //123456是wireless0的密码。
# select_network 0
# enable_network 0
# quit //执行q就会退出wpa_cli
2.查看wifi是否连接成功
# ifconfig wlan0
wlan0 Link encap:Ethernet HWaddr 90:bd:e6:36:6a:d6
inet addr:192.168.0.112 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::92bd:e6ff:fe36:6ad6/64 Scope: Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:699 errors:0 dropped:0 overruns:0 frame:0
TX packets:654 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:757221 TX bytes:75376
注意:说明已经连接成功,每次要看到下面log才能执行下一步,否则可能设置失败!
<3>CTRL-EVENT-SCAN-STARTED
<3>CTRL-EVENT-SCAN-RESULTS
注意:此种方式,重启后wifi密码会被清除;
4.此时连接到wifi adb
# adb tcpip 5555
# adb connect 192.168.0.112:5555
5.打开一个投屏软件,然后连接到另一个wifi(这样重启后就不会被清除)
PS:下面看下android命令行对wifi的操作
root@hammerhead:/data/misc/wifi # cat wpa_supplicant.conf
network={
ssid="hsyk-it"
psk="hs123456789"
key_mgmt=WPA-PSK
priority=1
}
svc wifi enable
关闭WIFI指令
svc wifi disable
echo "" >> wpa_supplicant.conf
echo "network={" >> wpa_supplicant.conf
echo "\tssid=\"WIFI的名字\"" >> wpa_supplicant.conf
echo "\tpsk=\"WIFI的密码\"" >> wpa_supplicant.conf
echo "\tkey_mgmt=WPA-PSK" >> wpa_supplicant.conf
echo "\tpriority=1" >> wpa_supplicant.conf
echo "}" >> wpa_supplicant.conf
打开WIFI指令
svc wifi enable
关闭WIFI指令
svc wifi disable
新手机:
drwxrwx--- wifi wifi 1970-05-02 02:05 sockets
-rw------- system system 41 1970-05-02 02:06 softap.conf
drwxrwx--- wifi wifi 1970-05-02 02:05 wpa_supplicant
打开wifi后:
-rw-rw---- system wifi 21 1970-05-02 02:36 entropy.bin
-rw-rw---- wifi wifi 312 1970-05-02 02:36 p2p_supplicant.conf
drwxrwx--- wifi wifi 1970-05-02 02:36 sockets
-rw------- system system 41 1970-05-02 02:06 softap.conf
drwxrwx--- wifi wifi 1970-05-02 02:05 wpa_supplicant
-rw-rw---- wifi wifi 311 1970-05-02 02:36 wpa_supplicant.conf
rm wpa_supplicant.conf
rm networkHistory.txt
rm entropy.bin
rm p2p_supplicant.conf
总结
以上所述是小编给大家介绍的Android通过命令连接wifi的方法(解决usb不能用问题),希望对大家有所帮助!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!