1. 程式人生 > >linux之wpa_cli命令使用詳解

linux之wpa_cli命令使用詳解

原文地址:http://blog.csdn.net/ylyuanlu/article/details/7634925

1: run wpa_supplicant first

use the following command:

       wpa_supplicant -Dwext -iwlan0 -C/data/system/wpa_supplicant -c/data/misc/wifi/wpa_supplicant.conf

(use “ps”to make sure wpa_supplicant is running )

2: Run the command line tool wpa_cli to connect wifi

wpa_cli -p/data/system/wpa_supplicant -iwlan0

       Then , it will let you set network interactively

       some common command:

       >scan = to scan the neighboring AP

       >scan_results = show the scan results

       >status = check out the current connection information

       >terminate = terminate wpa_supplicant

       >quit = exit wpa_cli

       >add_network = it will return a network id to you

       >set_network <network id> <variable> <value> = set network variables (shows

list of variables when run without arguments), success will return OK, or will return Fail

       >select_network <network id> = select a network (disable others)

       >disable_network <network id> = disable a network

       >enable_network <network id> = enable a network

3: example

       for AP that doesn`t have encryption

              >add_network      (It will display a network id for you, assume it returns 0)

              >set_network 0 ssid “666”

              >set_network 0 key_mgmt NONE

              >enable_network 0

              >quit

       if normal, we have connectted to the AP “666”, now you need a IP to access internet, for example:

              dhcpcd wlan0

              if everything is ok, it will get an IP & can access internet

       for AP that has WEP

              >add_network      (assume returns 1)

              >set_network 1 ssid “666”

              >set_network 1 key_mgmt NONE

              >set_network 1 wep_key0 “your ap passwork”(if usting ASCII, it need double quotation marks, if using hex, then don`t need the double quotation marks)

              >set_network 1 wep_tx_keyidx 0

              >select_network 1  (optional, remember, if you are connecting with another AP, you should select it to disable the another)

              >enable_network 1

              and then ,get an IP to access internet

       for AP that has WPA-PSK/WPA2-PSK

              >add_network      (assume returns 2)

              >set_network 2 ssid “666”

              >set_network 2 psk “your pre-shared key”

              >select_network 2  (optional, remember, if you are connecting with another AP, you should select it to disable the another)

              >enable_network 2

              there is still some others options to be set, but wpa_supplicant will choose the default for you, the default will include all we need to set

              and then ,get an IP to access internet

       for Hidden AP(補充)

        原則上應該只要在上面的基礎上去set_network netid scan_ssid 1即可,測試過無加密的Hidden AP,WEP/WPA/WPA2應該道理一樣

例項操作:

連線成功後的狀態

[email protected]:/usr/local/bin# iwconfig wlan0

wlan0     IEEE 802.11bgn  ESSID:"uslab_testing"  Nickname:"<[email protected]>"

          Mode:Managed  Frequency:2.432 GHz  Access Point: 84:C9:B2:88:0C:F2  

          Bit Rate:300 Mb/s   Sensitivity:0/0 

          Retry:off   RTS thr:off   Fragment thr:off

          Encryption key:****-****-****-****-****-****-****-****   Security mode:open

          Power Management:off

          Link Quality=98/100  Signal level=98/100  Noise level=0/100

          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0

          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

[email protected]:/usr/local/bin# wpa_cli

wpa_cli v0.7.3

Copyright (c) 2004-2010, Jouni Malinen <[email protected]> and contributors

This program is free software. You can distribute it and/or modify it

under the terms of the GNU General Public License version 2.

Alternatively, this software may be distributed under the terms of the

BSD license. See README and COPYING for more details.

Selected interface 'wlan0'

Interactive mode

scan_results

bssid / frequency / signal level / flags / ssid

84:c9:b2:88:0c:f2 2432 94  [WPA-PSK-TKIP+CCMP][WPA2-PSK-TKIP+CCMP][ESS]    uslab_testing

status

bssid=84:c9:b2:88:0c:f2

ssid=uslab_testing

id=0

mode=station

pairwise_cipher=CCMP

group_cipher=TKIP

key_mgmt=WPA2-PSK

wpa_state=COMPLETED

ip_address=192.168.0.101

連線過程

[email protected]:/usr/local/bin# wpa_supplicant -B -iwlan0 -Dwext -c /usr/local/etc/wpa_supplicant.conf

+871x_drv - drv_open, bup=0

 ===> FirmwareDownload91C() fw:Rtl819XFwImageArray_TSMC

fw_ver=v75, fw_subver=0, sig=0x88c0

fw download ok!

Set RF Chip ID to RF_6052 and RF type to 2.

GPIO_IN=09

eRfPowerStateToSet=0

IQK:Start!!!

Path A IQK Success!!

Path B IQK Success!!

Path A IQK Success!!

Path B IQK Success!!

IQK: final_candidate is 0

IQK: RegE94=101 RegE9C=2 RegEA4=fa RegEAC=3 RegEB4=101 RegEBC=7 RegEC4=fd RegECC=7

 Path A IQ Calibration Success !

Path B IQ Calibration Success !

pdmpriv->TxPowerTrackControl = 1

MAC Address from REG_MACID = 84:c9:b2:7d:64:2d

MAC Address = 84:c9:b2:7d:64:2d

-871x_drv - drv_open, bup=1

[rtw_wx_set_pmkid] IW_PMKSA_FLUSH!

set_mode = IW_MODE_INFRA

ioctl[SIOCSIWAP]: Operation not permitted

[rtw_wx_set_pmkid] IW_PMKSA_FLUSH!

[email protected]:/usr/local/bin# wpa_cli

wpa_cli v0.7.3

Copyright (c) 2004-2010, Jouni Malinen <[email protected]> and contributors

This program is free software. You can distribute it and/or modify it

under the terms of the GNU General Public License version 2.

Alternatively, this software may be distributed under the terms of the

BSD license. See README and COPYING for more details.

Selected interface 'wlan0'

Interactive mode

scan

OK

> survey done event(19)

<2>CTRL-EVENT-BSS-ADDED 0 84:c9:b2:88:0c:f2

<2>CTRL-EVENT-BSS-ADDED 1 02:e0:42:cb:c7:79

<2>CTRL-EVENT-SCAN-RESULTS

> scan_results

bssid / frequency / signal level / flags / ssid

84:c9:b2:88:0c:f2       2432    88      [WPA-PSK-TKIP+CCMP][WPA2-PSK-TKIP+CCMP][ESS]   uslab_testing

02:e0:42:cb:c7:79       2457    42      [WEP][IBSS]     ____13__1

>

add_network

0

>

set_network 0 ssid "uslab_testing"

OK

>

set_network 0 key_mgmt WPA-PSK

OK

>

set_network 0 psk "12345678"

OK

>

enable_network 0

OK

> survey done event(19)

wpa_set_auth_algs, AUTH_ALG_OPEN_SYSTEM

set_mode = IW_MODE_INFRA

 wpa_ie(length:22):

0x30 0x14 0x01 0x00 0x00 0x0f 0xac 0x02

0x01 0x00 0x00 0x0f 0xac 0x04 0x01 0x00

0x00 0x0f 0xac 0x02 0x00 0x00 0x78 0xff

=>rtw_wx_set_essid

ssid=uslab_testing, len=13

new candidate: uslab_testing(84:c9:b2:88:0c:f2) rssi:-54

rtw_select_and_join_from_scanned_queue: candidate: uslab_testing(84:c9:b2:88:0c:f2)

#### Opt_Ant_(B) , cur_Ant(B)

rtw_restructure_ht_ie IEEE80211_HT_CAP_MAX_AMSDU is set

<=rtw_wx_set_essid

link to new AP

<2>CTRL-EVENT-SCAN-RESULTS

<2>Trying to associate with 84:c9:b2:88:0c:f2 (SSID='uslab_testing' freq=2432 MHz)

> link to Realtek 96B

OnAuthClient

OnAssocRsp

report_join_res(1)

HW_VAR_BASIC_RATE: BrateCfg(0x15d)

WMM(0): 0, a42b

WMM(1): 0, a44f

WMM(2): 0, 5e4322

WMM(3): 0, 2f3222

HTOnAssocRsp

 ~~~~stastakey:unicastkey

 ~~~~stastakey:groupkey

==> rtw_set_key algorithm(2),keyid(1),key_mask(2)

update raid entry, mask=0xfffffff, arg=0xa0

rtl8192c_set_FwJoinBssReport_cmd mstatus(1)

SetFwRsvdPagePkt

Set RSVD page location to Fw.

=>mlmeext_joinbss_event_callback

<2>Associated with 84:c9:b2:88:0c:f2

<2>WPA: Key negotiation completed with 84:c9:b2:88:0c:f2 [PTK=CCMP GTK=TKIP]

<2>CTRL-EVENT-CONNECTED - Connection to 84:c9:b2:88:0c:f2 completed (auth) [id=0 id_str=]

save

OK

status

bssid=84:c9:b2:88:0c:f2

ssid=uslab_testing

id=0

mode=station

pairwise_cipher=CCMP

group_cipher=TKIP

key_mgmt=WPA2-PSK

wpa_state=COMPLETED

ip_address=192.168.0.101

quit

[email protected]:/usr/local/bin# udhcpc -i wlan0

udhcpc (v0.9.9-pre) started

Sending discover...

OnAction_back

OnAction_back, action=0

issue_action_BA, category=3, action=1, status=0

Sending select for 192.168.0.101...

Lease of 192.168.0.101 obtained, lease time 86400

adding dns 192.168.0.101

adding dns 192.168.0.102

[email protected]:/usr/local/bin#

[email protected]:/usr/local/bin# iwconfig wlan0

wlan0     IEEE 802.11bgn  ESSID:"uslab_testing"  Nickname:"<[email protected]>"

          Mode:Managed  Frequency:2.432 GHz  Access Point: 84:C9:B2:88:0C:F2  

          Bit Rate:300 Mb/s   Sensitivity:0/0 

          Retry:off   RTS thr:off   Fragment thr:off

          Encryption key:****-****-****-****-****-****-****-****   Security mode:open

          Power Management:off

          Link Quality=100/100  Signal level=100/100  Noise level=0/100

          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0

          Tx excessive retries:0  Invalid misc:0   Missed beacon:0

[email protected]:/usr/local/bin# ./wpa_cli

wpa_cli v0.7.3

Copyright (c) 2004-2010, Jouni Malinen <[email protected]> and contributors

This program is free software. You can distribute it and/or modify it

under the terms of the GNU General Public License version 2.

Alternatively, this software may be distributed under the terms of the

BSD license. See README and COPYING for more details.

Selected interface 'wlan0'

Interactive mode

disable_network 0

OK

<2>CTRL-EVENT-DISCONNECTED bssid=00:00:00:00:00:00 reason=0

> rtl8192c_set_FwJoinBssReport_cmd mstatus(0)

<2>CTRL-EVENT-BSS-REMOVED 0 84:c9:b2:88:0c:f2

 > status

wpa_state=DISCONNECTED

ip_address=192.168.0.101

terminate

OK

> (2)871x_drv - drv_close, bup=1, hw_init_completed=1

-871x_drv - drv_close, bup=1

rtl8192c_set_FwJoinBssReport_cmd mstatus(0)

'PING' command failed.

Connection to wpa_supplicant lost - trying to reconnect

quit

[email protected]:/usr/local/bin# ps

  PID  Uid     VmSize Stat Command

    1 root        528 S   init [3]  

    2 root            SW< [kthreadd]

    3 root            SW< [ksoftirqd/0]

    4 root            SW< [events/0]

    5 root            SW< [khelper]

   57 root            SW< [kblockd/0]

   63 root            SW< [ksuspend_usbd]

   68 root            SW< [khubd]

   71 root            SW< [kseriod]

   77 root            SW< [kmmcd]

  104 root            SW  [pdflush]

  105 root            SW  [pdflush]

  106 root            SW< [kswapd0]

  107 root            SW< [aio/0]

  215 root            SW< [kapmd]

  262 root            SW< [mtdblockd]

  332 root            SW< [w1_control]

  346 root            SW< [rpciod/0]

  424 root        388 S < /sbin/udevd --daemon

  445 root        584 S   /sbin/syslogd -n -C 64 -m 20

  447 root        564 S   /sbin/klogd -n

  470 root        928 S   -sh

  478 root            SW  [RTKTHREAD]

  485 root        764 R   ps

[email protected]:/usr/local/bin#

相關推薦

linux awk命令

數學函數 mat loop 多次 finished 數組結構 save pre 新的 awk是一種程序語言,對文檔資料的處理具有很強的功能。awk名稱是由它三個最初設計者的姓氏的第一個字母而命名的: Alfred V. Aho、Peter J. We i n b e rg

Linuxfind命令

Linux find find:實時查找工具,通過遍歷指定起始路徑下文件系統層級結構完成文件查找: 工作特性: 查找速度略慢: 精確查找: 實時查找: 用法: find [OPTIONS][查找起始路徑][查找條件

玩轉LINUXsed命令

用戶 常見 mail 括號 {} int 緩沖 復雜 commands Linux sed命令是利用script來處理文本文件。 sed可依照script的指令,來處理、編輯文本文件。 Sed主要用來自動編輯一個或多個文件;簡化對文件的反復操作;編寫轉換程序等。 執行時,s

Linuxexpr命令

expr命令:     expr命令是一個手工命令列計數器,用於在UNIX/LINUX下求表示式變數的值,一般用於整數值,也可用於字串。   –格式為:     expr Expression(命令讀入Expression 引數,計算它的值,然後將結果寫入到標準輸出)   –引數應用規則:     用空格隔開

Linuxman命令及中文漢化

使用方法 Linux man中的man就是manual的縮寫,用來檢視系統中自帶的各種參考手冊 使用方法: man command 示例: [[email protected]_0_13_centos ~]# man ls LS(1)

Linux Cut命令

cut是一個選取命令,就是將一段資料經過分析,取出我們想要的。一般來說,選取資訊通常是針對“行”來進行分析的,並不是整篇資訊分析的。 (1)其語法格式為:cut  [-bn] [file] 或 cut [-c] [file]  或  cut [-df] [file]

Linuxsed命令

sed是一種流編輯器,它是文字處理中非常好的工具,能夠完美的配合正則表示式使用,功能不同凡響。處理時,把當前處理的行儲存在臨時緩衝區中,稱為“模式空間”(pattern space),接著用sed命令處理緩衝區中的內容,處理完成後,把緩衝區的內容送往螢幕。接著處理下一行,

Linuxlocate命令

檔案搜尋命令:locate(只能搜檔名) 用法  locate 檔名在後臺數據庫中安檔名搜尋,搜尋速度比find更快,但對於剛建立的檔案,使用該命令進行查詢將會搜尋不到所建立的檔案,例如: 如果想使剛建立的檔案被locate命令搜尋到,可以使用updatedb命令,更新ml

Linuxtouch命令

在Linux中,touch命令主要是用於新建一個不存在的檔案或者是對於檔案的時間戳進行修改; (1)使用touch命令新建一個不存在的檔案 使用touch新建了一個檔案,然後使用ls -a進行檔案目

Linuxawk命令

AWK介紹 0.awk有3個不同版本: awk、nawk和gawk,未作特別說明,一般指gawk。 1.awk語言的最基本功能是在檔案或字串中基於指定規則來分解抽取資訊,也可以基於指定的規則來輸出資料。完整的awk指令碼通常用來格式化文字檔案中的資訊。 2.三種方式呼叫awk 1) awk [opion]

linuxwpa_cli命令使用

原文地址:http://blog.csdn.net/ylyuanlu/article/details/7634925 1: run wpa_supplicant first use the following command:        wpa_supplica

linux文本處理三劍客grep命令

gawk 軟件 upper edit 進制 使用 第一個 空格 earch Linux文本處理三劍客之grep grep:文本過濾(模式:pattern)工具 grep, egrep, fgrep(不支持正則表達式搜索) sed:stream editor,

Linux三劍客awk命令

awk簡單入門 awk是一個強大的文字分析工具,相對於grep的查詢,sed的編輯,awk在其對資料分析並生成報告時,顯得尤為強大。簡單來說awk就是把檔案逐行的讀入,以空格為預設分隔符將每行切片,切開的部分再進行各種分析處理。 使用方法: awk '{pattern + a

Linux基礎知識dd命令

本文先簡要介紹dd的引數,然後通過幾個例項介紹dd的應用,這些素材整理來源於網路。 dd 是 Linux/UNIX 下的一個非常有用的命令,其作用是用指定大小的塊拷貝一個檔案,並在拷貝的同時進行指定的轉換。 1. 命令簡介 dd 的主要引數選項: 指定數字的地方若以下列字元結尾乘以相應的數字: b=

Linux系列 tar 命令

tar 是 unix/linux下的打包器 【解壓】 輸入命令: # tar  -zxvf  filename.tar.gz 引數解釋: z :表示 tar 包是被 gzip 壓縮過的 (字尾是.tar.gz),所以解壓時需要用 gu

Linux命令——Date命令

date命令的幫助資訊  [[email protected] source]# date --help 用法:date [選項]... [+格式]  或:date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]] 以

linux命令dd命令和/dev/zero、/dev/null

主要內容來自:http://www.cnblogs.com/dkblog/archive/2009/09/18/1980715.html dd 是 Linux/UNIX 下的一個非常有用的命令,作用是用指定大小的塊拷貝一個檔案,並在拷貝的同時進行指定的轉換(convert

Linux 命令 scp 命令

Linux 命令之 scp 命令詳解 一、scp 簡介 scp 命令用於不同主機之間複製檔案和目錄。 scp 是 secure copy 的縮寫,是 基於 ssh 協議進行安全的遠端檔案拷貝命令。 scp 想要免密進行復制,需要傳送祕鑰給相應的節點。 scp 是加密的,rcp 是不加密的,scp 是 rcp

Linux學習iostat命令

  我們可以用iostat 命令來監視系統輸入/輸出、裝置負載,這通過觀察與它們的平均傳送速率相關的物理磁碟的活動時間 來實現。iostat 命令生成的報告可以用來更改系統配置,從而更好地平衡物理磁碟和介面卡之間的輸入/輸出負載。當Linux系 統出現效能問題時,用iostat工具檢視程序IO請求下發的數量、

linux下cat命令

forever ron localhost root sta testing 幫助 查看 一點 1、cat 顯示文件連接文件內容的工具; cat 是一個文本文件查看和連接工具。查看一個文件的內容,用cat比較簡單,就是cat 後面直接接文件名。 比如: de>[[