惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Schneier on Security
F
Fortinet All Blogs
博客园_首页
The GitHub Blog
The GitHub Blog
V
Visual Studio Blog
D
DataBreaches.Net
aimingoo的专栏
aimingoo的专栏
爱范儿
爱范儿
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
N
Netflix TechBlog - Medium
阮一峰的网络日志
阮一峰的网络日志
P
Proofpoint News Feed
D
Docker
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
The Cloudflare Blog
罗磊的独立博客
云风的 BLOG
云风的 BLOG
Microsoft Azure Blog
Microsoft Azure Blog
T
The Exploit Database - CXSecurity.com
博客园 - 三生石上(FineUI控件)
量子位
The Last Watchdog
The Last Watchdog
MyScale Blog
MyScale Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Blog of Author Tim Ferriss
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
小众软件
小众软件
Cloudbric
Cloudbric
博客园 - 司徒正美
H
Help Net Security
人人都是产品经理
人人都是产品经理
Application and Cybersecurity Blog
Application and Cybersecurity Blog
L
LangChain Blog
Latest news
Latest news
M
MIT News - Artificial intelligence
T
Threat Research - Cisco Blogs
博客园 - Franky
S
Security Affairs
W
WeLiveSecurity
F
Full Disclosure
Know Your Adversary
Know Your Adversary
Google DeepMind News
Google DeepMind News
The Hacker News
The Hacker News
Cyberwarzone
Cyberwarzone
美团技术团队
PCI Perspectives
PCI Perspectives
C
Check Point Blog
Spread Privacy
Spread Privacy

博客园 - fand

mysql分别排名 Google Adsense优化 博文阅读密码验证 - 博客园 测试freebsd上的pf防火墙和linux上的iptables防火墙-zz 安装ffmpeg FreeBSD6安装之AMP的安装 - fand - 博客园 MySQL的性能调优工具:比mysqlreport更方便的tuning-primer.sh 支撑1000万pv的数据库缓存解决方案 博文阅读密码验证 - 博客园 Boost 库中的实用工具类使用 梦断代码 老生常谈 LAMP 系统性能调优 基于反相代理的Web缓存加速——可缓存的系统设计 LDAP介绍 CVS使用手册 学习Java需要达到的30个目标 editplus使用技巧 linux平台使用oracle 9I数据库 PHP程序优化探密
ubuntu下wpa_supplicant使用
fand · 2011-04-19 · via 博客园 - fand

目的:

  远端(php)控制网络设置(命令行shell)。

(Network Manager会影响wpa_supplicant,所以需要卸载。)

使用平台

Ubuntu 10.04 LTS

GNU/Linux i686 2.6.32-24-generic

调用的资源

a)       显示网络状态

/sbin/ifconfig

Cat /etc/resolv.conf

/sbin/route –n

b)       显示无线信号

/sbin/iwlist wlan0 scan

c)       写入地址信息

ifconfig eth0 192.168.1.101 netmask 255.255.255.0

route add default gw 192.168.1.1

echo "nameserver 192.168.1.1 \n nameserver192.168.1.1" > /etc/resolv.conf

/etc/init.d/networking restart

d)       写入无线的用户名和密码

    把用户名密码写入到/etc/wpa_supplicant.conf

使用前配置:

a)       卸载Network Manager
apt-get remove NetworkManager

b)       拷贝wpa.sh/etc/wpa.sh

#!/bin/bash
#
## BEGIN INIT INFO
#
 Provides:          wpa
#
 Required-Start:    $network $syslog $local_fs
#
 Required-Stop:     $network $syslog $local_fs
#
 Default-Start:     2 3 4 5
#
 Default-Stop:      0 1 6
#
 Short-Description: Start/stop script for wpa supplicant
#
 Description:       Custom start/stop script for wpa_supplicant.
#
## END INIT INFO

SELF
=`basename $0`
WPA
=wpa_supplicant
PROGRAM
=/sbin/${WPA}
CONF
=/etc/${WPA}.conf
INTERFACE
=wlan0
DRIVER
=wext
DAEMONMODE
="-B"
LOGFILE
=/var/log/$WPA.logfunction start() {# TODO: Support multiple interfaces and drivers
    OPTIONS="-c $CONF -i $INTERFACE -D $DRIVER $DAEMONMODE"## You can remove this if you are running 8.10 and up.
    # Ubuntu 8.10 and up doesn't need the -w anymore..
    # And the logfile option is not valid on 8.04 and lower
    local ver=$(lsb_release -sr | sed -e 's/\.//g');
    [ 
$ver -lt 810 ] && OPTIONS="$OPTIONS -w" && LOGFILE=""
    
##

    
# Log to a file
    [ -"$LOGFILE" ] && OPTIONS="$OPTIONS -f $LOGFILE"

    echo 

" * Starting wpa supplicant"
    eval 
$PROGRAM $OPTIONS
}
function stop() {
    echo 
" * Stopping wpa supplicant"
    pkill 
$PROGRAM
}
function debug() {
    stop
    DAEMONMODE
="-ddd"
    start
}
function restart() {
    stop
    start
}
function status() {
    pgrep 
-lf $PROGRAM
}
function usage() {
    echo 
"Usage: $SELF <start|stop|status|debug>"
    
return 2
}

case 

$1 in
    start
|stop|debug|status) $1 ;;
    
*) usage ;;
esac

c)       新建配置文件/etc/wpa_supplicant.conf

ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group
=0
eapol_version
=2
ap_scan
=1
fast_reauth
=1
country
=NL

network

={
  ssid
="ddd"
  psk
="xxx"
  scan_ssid
=1
}

d)       修改/etc/network/interfaces

auto lo
iface lo inet loopback

auto wlan0
iface wlan0 inet dhcp
pre

-up /etc/wpa.sh start
post
-down /etc/wpa.sh stop

/etc/init.d/networking restart

重启网卡报错

Failed to bring up wlan0

发现重启网络时,wpa还没有关闭,所以起不来。

/etc/init.d/networking stop

sleep 5

/etc/init.d/networking start

问题暂时解决

权限问题:

chmod u+s /sbin/iwlist

chmod u+s /sbin/route

chmod u+s /sbin/ifconfig

太多了,害怕列举不玩。而且可能有安全问题。

针对www-data用户,sudo免输密码

visudo

www-data ALL=(ALL) NOPASSWD: NOPASSWD: ALL