解决办法:清空/var/lib/dhclient/dhclient.leases文件里的所有内容 # sudo dhclient -r //release ip 释放IP # sudo dhclient //获取IP 清空dns缓存,(重启dns服务) # service nscd restart 或是 # /etc/init.d/nscd restart 然后重启网络,service network restart获取ip成功
#打开无线网卡电源
iwconfig wlan0 txpower on
 
#列出区域内的无线网络
iwlist wlan0 scan
 
#假设要连接到网络MyHome(即essid为MyHome的网络),那么输入命令
iwconfig wlan0 essid "MyHome"
 
#如果网络是加密的,密码是0123456789,那么就输入命令
iwconfig wlan0 essid "MyHome" key 0123-4567-89
 
#如果正常的话,输入下面命令就可以看到连接正常的各项参数了。
iwconfig wlan0
 
#启用无线网卡的网络
ifconfig wlan0 up
 
#如果是用DHCP获取IP的,那么用dhclient或dhcpcd获取ip
dhclient wlan0 #或 dhcpcd wlan0
 
#现在无线网卡应该可以正常使用了

第一种是用 iwconfig 命令,但是这个命令在连接时经常报错,然后无法连接,这里便不做说明了。

第二种是使用 wpa_cli (注:我碰到的情况是,这个命令只可以在恢复模式下的shell中使用,在gnome桌面中是不管用的)

操作步骤:

shell 中输入 wpa_cli 进入交互,然后输入

add_network
# 执行后会返回一个数字(一般是0),下面会用到,暂且称为 NID

set_network NID ssid “WIFI SSID,根据你的网络环境填写”

set_network NID psk “无线密码”

enable_network NID
#启用网络,成功后会返回 CONNECT TO XXXX的

然后就可以输入q退出了

退出后使用 dhclient wlan0 获取一下网络地址就可以使用了

目前可以使用wireless-tools 或wpa_supplicant工具来配置无线网络。请记住重要的一点是,对无线网络的配置是全局性的,而非针对具体的接口。

wpa_supplicant是一个较好的选择,但缺点是它不支持所有的驱动。请浏览wpa_supplicant网站获得它所支持的驱动列表。另外,wpa_supplicant目前只能连接到那些你已经配置好ESSID的无线网络。wireless-tools支持几乎所有的无线网卡和驱动,但它不能连接到那些只支持WPA的AP。

经过编译后的wpa_supplicant源程序可以看到两个主要的可执行工具:wpa_supplicant和wpa_cli。wpa_supplicant是核心程序,它和wpa_cli的关系就是服务和客户端的关系:后台运行wpa_supplicant,使用wpa_cli来搜索、设置、和连接网络。

如何用wpa_supplicant使能一个wifi连接?

Step by step:

1、运行wpa_supplicant程序;

执行:/system/bin/wpa_supplicant -d -Dwext -iwlan0 -c/data/misc/wifi/wpa_supplicant.conf

其中:

-d :增加调试信息

-Dwext :wext,驱动名称

-iwlan0 :wlan0,网络接口名称

/system/bin/wpa_supplicant :wpa_supplicant可执行程序path

/data/misc/wifi/wpa_supplicant.conf :wpa_supplicant的配置文件path

2、运行命令行工具wpa_cli ;

执行 :wpa_cli -iwlan0 -p/data/system/wpa_supplicant

注,-p/data/system/wpa_supplicant中的wpa_supplicant并不是可执行程序,而是个控制套接字。

此时会进入交互模式。其中交互模式的命令如下表:

Full command

Short command

Description

status

stat

displays the current connection status

disconnect

disc

prevents wpa_supplicant from connecting to any access point

quit

q

exits wpa_cli

terminate

term

kills wpa_supplicant

reconfigure

recon

reloads wpa_supplicant with the configuration file supplied (-c parameter)

scan

scan

scans for available access points (only scans it, doesn't display anything)

scan_result

scan_r

displays the results of the last scan

list_networks

list_n

displays a list of configured networks and their status (active or not, enabled or disabled)

select_network

select_n

select a network among those defined to initiate a connection (ie select_network 0)

enable_network

enable_n

makes a configured network available for selection (ie enable_network 0)

disable_network

disable_n

makes a configured network unavailable for selection (ie disable_network 0)

remove_network

remove_n

removes a network and its configuration from the list (ie remove_network 0)

add_network

add_n

adds a new network to the list. Its id will be created automatically

set_network

set_n

shows a very short list of available options to configure a network when supplied with no parameters.

See next section for a list of extremely useful parameters to be used with set_network and get_network.

get_network

get_n

displays the required parameter for the specified network. See next section for a list of parameters

save_config

save_c

saves the configuration

设置网络的基本格式:set_network <network id> <key> <parameter> [<parameter>]

显示网络信息的基本格式:get_network <network id> <key>

相应的参数如下表:

Key

Description

Parameters

ssid

Access point name

string

id_str

String identifying the network

string

priority

Connection priority over other APs

number (0 being the default low priority)

bssid

Mac address of the access point

mac address

scan_ssid

Enable/disbale ssid scan

0, 1, 2

key_mgmt

Type of key management

WPA-PSK, WPA_EAP, None

pairwise

Pairwise ciphers for WPA

CCMP, TKIP

group=TKIP

Group ciphers for WPA

CCMP, TKIP, WEP104, WEP40

psk

Pre-Shared Key (clear or encrypted)

string

wep_key0

WEP key (up to 4: wep_key[0123])

string

eap

Extensible Authentication Protocol

MD5, MSCHAPV2, OTP, GTC, TLS, PEAP, TTLS

identity

EAP identity string

string

password

EAP password

string

ca_cert

Pathname to CA certificate file

/full/path/to/certificate

client_cert

Pathname to client certificate

/full/path/to/certificate (PEM/DER)

private_key

Pathname to a client private key file

/full/path/to/private_key (PEM/DER/PFX)

eg.1、连接无加密的AP

>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

eg.2、连接WEP加密AP

>add_network   (assume return 1)

>set_network 1 ssid "666"

>set_network 1 key_mgmt NONE

>set_network 1 wep_key0 "your ap password"

>enable_network 1

eg.3、连接WPA-PSK/WPA2-PSK加密的AP

>add_network   (assume return 2)

>set_network 2 ssid "666"

>set_network 2 psk "your pre-shared key"

>enable_network 2

到此,wifi模块就能连接上AP了。

3、以上是通过命令行工具wpa_cli来实现wifi网络的连接。当然,也可以通过wpa_supplicant的配置文件来实现连接。

再回顾下运行wpa_supplicant时执行的命令:

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

我们在执行时加上了-c/data/misc/wifi/wpa_supplicant.conf,我们可以将我们要连接的AP的设置以一定的格式写入wpa_supplicant.conf配置文件中即可。

eg.

ctrl_interface=DIR=/data/system/wpa_supplicant GROUP=system update_config=1

network={

ssid="my access point"

proto=WPA

key_mgmt=WPA-PSK

psk="you pass words"

}

iwlist,IweventS,iwspy,

解决办法:清空/var/lib/dhclient/dhclient.leases文件里的所有内容 # sudo dhclient -r //release ip 释放IP # sudo dhclient //获取IP 清空dns缓存,(重启dns服务) # service nscd restart 或是 # /etc/init.d/nscd restart 然后重启网络,service network restart获取ip成功

iwconfig的更多相关文章

  1. 无线网卡的查看与配置——iw,iwconfig,ethtool

    摘要:在linux上,我们经常需要把一台笔记本设置成一个共享wifi上网的路由器.如果我们需要把本机配置成一台无线AP,就需要查看网卡的相关信息和进行对应配置.其中iw.iwconfig和ethtoo ...

  2. Linux下的iwpriv(iwlist、iwconfig)的简单应用

    无线网络飞速发展的今天,许多设备都提供了连接无线网络的功能. 那么Linux下的wifi到底该怎么配置.连接呢?? 开始配置之前,我们要说说iw家族.iw是linux下常用的wifi配置工具,网上有相 ...

  3. wifi测试相关(iwconfig,WPA Supplicant用法)

    iwconfig用法 1.打开无线网卡电源 iwconfig wlan0 txpower no 2.列出区域内的无线网络 iwconfig wlan0 scan 3.假设要连接到网络myhome(即e ...

  4. wpa_supplicant使用笔记-wpa_cli iwconfig

    还在搞8634,看不到头了..唉.wireless_tools的缺点是不支持WPA认证,所以有必要把wpa_supplicant也移植过来.无线 网卡是基于zydas芯片的,正好可以在网上搜到wpa_ ...

  5. 嵌入式wifi iwconfig编译

    转载自:http://blog.sina.com.cn/s/blog_546ced060101cmru.html     移植wifi无线网卡到mini2440上全过程 前段时间移植了U-boot和l ...

  6. linux下使用无线网卡的命令行方法(wifi,iwconfig)

    原文地址:linux下使用无线网卡的命令行方法(wifi,iwconfig) 作者:andyhzw (1)首先关闭开发板的有线网卡 [root@FriendlyARM /]# ifconfig eth ...

  7. iwlist/iwconfig/iw命令

    1.iwlist 命令:用于对/proc/net/wireless文件进行分析,得出无线网卡相关信息 # iwlist wlan0 scanning 搜索当前无线网络 # iwlist wlan0 f ...

  8. Iwconfig/aircrack-ng

    BT5 aircrack-ng破解无线密码(wpa/wep) - 星明月稀 - 博客频道 - CSDN.NET             BT5 aircrack-ng破解无线密码(wpa/wep) - ...

  9. Linux常用命令操作

    系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器的处理器架构(2) uname -r 显示正在使用的内核版本 dmidecode -q 显示硬件系统部件 - (SMBIOS ...

随机推荐

  1. Ubuntu打开core dump

    输入ulimit -a 如果core file size为0,那就说明没有打开core dump,尽管你的程序crash的时候会显示core dumped,但实际上不会生成core file 输入ul ...

  2. ms17010漏洞复现-2003

    先使用Smbtouch模块检测一下是否有漏洞. 然后使用Doublepulsar写一个shellcode到本地. 生成成功后的截图: 再使用EternalRomance植入Doublepulsar后门 ...

  3. scala,spark练习题提高

    1.求每家公司有哪些产品 val arr3 = List("Apache" -> "Spark", "Apache" -> &q ...

  4. repcached与mysql缓存測试

    使用gem安装mysql引擎 gem install mysql(假设安装失败.请查找一些依赖组建是否安装,比如mysql-devel) 编写ruby脚本,先获取mysql数据,之后从memcache ...

  5. 素数 + 背包 - SGU 116. Index of super-prime

    Index of super-prime Problem's Link Mean: 如果一个素数所在的位置还是素数,那么这个素数就是超级素数,比如3在第2位置,那么3就是超级素数. 现在给你一个数,求 ...

  6. Linux - 静默安装oracle数据库总结

    Web服务器上面的Linux一般是不会有图形界面的,所有通过图形界面来安装Linux的方式在没有图形界面的Linux上面是行不通的,我们要使用的安装方式叫做Linux的静默安装.即在没有图形界面的Li ...

  7. 【BZOJ】1696: [Usaco2007 Feb]Building A New Barn新牛舍(贪心)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1696 原题要求min(sum{|x-xi|+|y-yi|}),且一定要看题:“没有两头牛的吃草位置是 ...

  8. VS2013和VS2010工具集和字符集

    不兼容要改工具集 有时也要改字符集 位置:项目->项目属性->配置属性.常规 或者先选中项目,再同上.  vs平台工具集 vs2010版本之后支持使用之前的版本编译,可以在 属性-> ...

  9. hdu 3085(双向bfs)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3085 思路:双向广搜,每次从M出发,搜三步,从G出发,搜一步,然后就是判断是否走到对方已经走过的格子, ...

  10. 剑指 offer set 24 扑克牌的顺子

    题目 从扑克牌中任意抽取出 5 张牌, 判断是不是顺子, 并且大小王可以看成任意的数字 思路 1. 把大小王当做 0 插入到数组中, 然后对数组排序 2. 统计相邻两个数之间的空隙数, 若空隙数大于 ...