Linux WIFI 扫描

 启动wifi服务

    connmanctl disable wifi
    connmanctl enable wifi
    ifconfig wlan0 down 
    ifconfig wlan0 up

wpa_supplicant包含两个主要的可执行工具:wpa_supplicant和wpa_cli。

wpa_supplicant是核心程序,它和wpa_cli的关系就是服务和客户端的关系:后台运行wpa_supplicant,使用wpa_cli来搜索、设置、和连接网络。

大部分情况下编辑好配置文件,运行wpa_supplicant 就可以连通网络了,

创建一个  wpa_supplicant.conf

可以     

echo "update_config=1" > /tmp/ema_wpa_supplicant.conf
echo "ctrl_interface=/var/run/wpa_supplicant" >> /tmp/ema_wpa_supplicant.conf

vi /tmp/wpa_supplicant.conf 
ctrl_interface=/var/run/wpa_supplicant
update_config=1


其中,update_config=1使能配置更改。

 关闭  wpa_supplicant

 kill -9 `pgrep wpa_supplicant`

wpa_supplicant 命令如下

usage:
  wpa_supplicant [-BddhKLqqtuvW] [-P<pid file>] [-g<global ctrl>] \
        [-G<group>] \
        -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] [-p<driver_param>] \
        [-b<br_ifname>] [-e<entropy file>] [-f<debug file>] \
        [-o<override driver>] [-O<override ctrl>] \
        [-N -i<ifname> -c<conf> [-C<ctrl>] [-D<driver>] \
        [-m<P2P Device config file>] \
        [-p<driver_param>] [-b<br_ifname>] [-I<config file>] ...]

drivers:
  nl80211 = Linux nl80211/cfg80211
  wext = Linux wireless extensions (generic)
  wired = Wired Ethernet driver
options:
  -b = optional bridge interface name
  -B = run daemon in the background
  -c = Configuration file
  -C = ctrl_interface parameter (only used if -c is not)
  -d = increase debugging verbosity (-dd even more)
  -D = driver name (can be multiple drivers: nl80211,wext)
  -e = entropy file
  -f = log output to debug file instead of stdout
  -g = global ctrl_interface
  -G = global ctrl_interface group
  -h = show this help text
  -i = interface name
  -I = additional configuration file
  -K = include keys (passwords, etc.) in debug output
  -L = show license (BSD)
  -m = Configuration file for the P2P Device interface
  -M = start describing new matching interface
  -N = start describing new interface
  -o = override driver parameter for new interfaces
  -O = override ctrl_interface parameter for new interfaces
  -p = driver parameters
  -P = PID file
  -q = decrease debugging verbosity (-qq even less)
  -t = include timestamp in debug messages
  -u = enable DBus control interface
  -v = show version
  -W = wait for a control interface monitor before starting
example:
  wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant.conf

 其中最常用的为:

-i 指定端口

-c 指定配置文件

-D 指定使用的wifi驱动

我们这里只指定端口和配置文件,驱动使用默认的。

 查看网卡端口 ifconfig

使用以下命令配置
wpa_supplicant  -i wlan0 -D nl80211 -c/tmp/ema_wpa_supplicant.conf -B

 

wpa_cli -i wlan0 scan  扫描

sleep 10

wpa_cli -i wlan0 scan_results | grep "$2"  

 

 这样就测试WiFi成功

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值