博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Qt wifi helper script
阅读量:4058 次
发布时间:2019-05-25

本文共 4754 字,大约阅读时间需要 15 分钟。

Start

yantai:/home/shell.albert/project/build-EAVCapturex86-Desktop_Qt_5_3_GCC_64bit-Debug/bin # ./zwpactl.sh  start

need ssid and psk
yantai:/home/shell.albert/project/build-EAVCapturex86-Desktop_Qt_5_3_GCC_64bit-Debug/bin # ./zwpactl.sh  start zhangshaoyan
need ssid and psk
yantai:/home/shell.albert/project/build-EAVCapturex86-Desktop_Qt_5_3_GCC_64bit-Debug/bin # ./zwpactl.sh  start zhangshaoyan  beijing12345
Successfully initialized wpa_supplicant

yantai:/home/shell.albert/project/build-EAVCapturex86-Desktop_Qt_5_3_GCC_64bit-Debug/bin #

Check

yantai:/home/shell.albert # ps aux | grep "wpa"

root       948  0.0  0.0  30836  3772 ?        Ss   08:37   0:00 /usr/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -u -f /var/log/wpa_supplicant.log
root     13358  0.0  0.0  10524  1624 pts/3    S+   15:44   0:00 grep --color=auto wpa
yantai:/home/shell.albert # ps aux | grep "wpa"
root       948  0.0  0.0  30836  3772 ?        Ss   08:37   0:00 /usr/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -u -f /var/log/wpa_supplicant.log
root     13419  0.0  0.0  30836  2168 ?        Ss   15:45   0:00 wpa_supplicant -iwlp5s0 -czwpa.conf -P/var/run/zwpa.pid -B
root     13429  0.0  0.0  10524  1528 pts/3    S+   15:45   0:00 grep --color=auto wpa
yantai:/home/shell.albert # cat /var/run/zwpa.pid
13419
yantai:/home/shell.albert #

Stop

yantai:/home/shell.albert/project/build-EAVCapturex86-Desktop_Qt_5_3_GCC_64bit-Debug/bin # ./zwpactl.sh  stopyantai:/home/shell.albert/project/build-EAVCapturex86-Desktop_Qt_5_3_GCC_64bit-Debug/bin #

yantai:/home/shell.albert # cat /var/run/zwpa.pid
cat: /var/run/zwpa.pid: No such file or directory
yantai:/home/shell.albert # ps aux | grep "wpa"
root       948  0.0  0.0  30836  3772 ?        Ss   08:37   0:00 /usr/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -u -f /var/log/wpa_supplicant.log
root     13455  0.0  0.0  10524  1568 pts/3    S+   15:45   0:00 grep --color=auto wpa
yantai:/home/shell.albert #

wpa_supplicant is also need dhcient to get IP from DHCP server.

yantai:/home/shell.albert # dhclient -v wlp5s0

Internet Systems Consortium DHCP Client 4.2.6
Copyright 2004-2014 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/wlp5s0/00:26:c7:24:28:f4
Sending on   LPF/wlp5s0/00:26:c7:24:28:f4
Sending on   Socket/fallback
DHCPDISCOVER on wlp5s0 to 255.255.255.255 port 67 interval 2 (xid=0x39b72d2e)
DHCPDISCOVER on wlp5s0 to 255.255.255.255 port 67 interval 4 (xid=0x39b72d2e)
DHCPDISCOVER on wlp5s0 to 255.255.255.255 port 67 interval 11 (xid=0x39b72d2e)
DHCPDISCOVER on wlp5s0 to 255.255.255.255 port 67 interval 20 (xid=0x39b72d2e)
DHCPDISCOVER on wlp5s0 to 255.255.255.255 port 67 interval 7 (xid=0x39b72d2e)
DHCPDISCOVER on wlp5s0 to 255.255.255.255 port 67 interval 12 (xid=0x39b72d2e)
DHCPREQUEST on wlp5s0 to 255.255.255.255 port 67 (xid=0x39b72d2e)
DHCPOFFER from 192.168.0.1
DHCPACK from 192.168.0.1 (xid=0x39b72d2e)
bound to 192.168.0.148 -- renewal in 2921 seconds.
yantai:/home/shell.albert # echo $?
0
yantai:/home/shell.albert #

Come on baby,read the following script carefully! Enjoy it !

#!/bin/bash

#this script is used to control wpa_supplicant daemon server.
#for EAVCapture iMX6 project.
#by zhangshaoyan at May 26,2015.
WPABIN=wpa_supplicant
WIRELESSNAME=wlp5s0 #wlan0
CONFILE=zwpa.conf
PIDFILE=/var/run/zwpa.pid
DHCLIENT=dhclient
#usage:
#zwpactl.sh initial:install driver.
#zwpactl.sh start: start wpa_supplicant.
#zwpactl.sh stop: stop wpa_supplicant.
function usage()
{
    echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
    echo "Usage:$0 <commands>."
    echo "supported commands:"
    echo "initial: install WiFi driver module."
    echo "start: start wpa_supplicant daemon server."
    echo "stop: stop wpa_supplicant."
    echo "by 13522296239"
    echo "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"
}
#generate .conf file.
#here is bug exist,do not keep space or Tab before EOF.
function generateConfFile()
{
cat<<EOF >zwpa.conf
ctrl_interface=/var/run/wpa_supplicant
network={
    ssid="$1"
    psk="$2"
}
EOF
}
#at least need 1 parameter.
if [ $# -lt 1 ];then
    usage
    exit -1
fi
if [ $1 = "initial" ];then
    #insmod wifi driver.
    #this should be done at the OS starts before GUI starts.
    insmod rtl8188.ko
elif [ $1 = "start" ];then
    if [ $# -lt 3 ];then
        echo "ZSY:need ssid and psk"
        exit -1
    fi
    #dump out a config file.
    generateConfFile $2 $3
    #start the daemon server.
    ${WPABIN} -i${WIRELESSNAME} -c${CONFILE} -P${PIDFILE} -B
    if [ $? -eq 0 ];then
        echo "ZSY:start success"
        
        #start dhcp client.
        ${DHCLIENT} -v ${WIRELESSNAME}
        if [ $? -ne 0 ];then
            echo "ZSY:dhclient fails"
            exit -1
        fi    
    else
        echo "ZSY:start failed!"
        exit -1
    fi    
elif [ $1 = "stop" ];then
    if [ -x $PIDFILE ];then
        kill `cat $PIDFILE`
        rm -rf $PIDFILE
    fi
else
    echo "ZSY:Unknown command"
    exit -1
fi
#success here.
echo "ZSY:wpa ctrl ends with success"
exit 0
#the end of file by zhangshaoyan.

转载地址:http://afzji.baihongyu.com/

你可能感兴趣的文章
Linux 粘滞位 suid sgid
查看>>
C#控件集DotNetBar安装及破解
查看>>
Winform皮肤控件IrisSkin4.dll使用
查看>>
Winform多线程
查看>>
C# 托管与非托管
查看>>
Node.js中的事件驱动编程详解
查看>>
mongodb 命令
查看>>
MongoDB基本使用
查看>>
mongodb管理与安全认证
查看>>
nodejs内存控制
查看>>
nodejs Stream使用中的陷阱
查看>>
MongoDB 数据文件备份与恢复
查看>>
数据库索引介绍及使用
查看>>
MongoDB数据库插入、更新和删除操作详解
查看>>
MongoDB文档(Document)全局唯一ID的设计思路
查看>>
mongoDB简介
查看>>
Redis持久化存储(AOF与RDB两种模式)
查看>>
memcached工作原理与优化建议
查看>>
Redis与Memcached的区别
查看>>
redis sharding方案
查看>>