感谢您的回复,这几篇帖子我已经浏览了,关于wpasupplicant的文章,我确实没怎么看懂,难度很大,而且都是E问,理解起来不是很透彻,我想我考虑的功能应该根据此篇文章能够实现,只是如下部分应该怎么理解:
=============================================================================================
Note to Kubuntu users: No editing of files needed. Just make sure wpasupplicant is installed and start knetworkmanager from the Internet menu.
Edit /etc/wpa_supplicant.conf to include your network. The info to include can be generated with wpa_passphrase (i) (although this is optional, it saves the supplicant having to generate the preshared key (PSK) each time it is started):
IconsPage/example.png
dennis@mirage:~$ wpa_passphrase NetworkEssid
# reading passphrase from stdin
TextPassphrase
network={
ssid="NetworkEssid"
#psk="TextPassphrase"
psk=945609a382413e64d57daef00eb5fab3ae228716e1e440981c004bc61dccc98c
}
(i) Requiring wpa_passphrase to prompt for the passphrase, rather than providing it as a command line argument, prevents the phrase from being stored insecurely in your shell's history.
Then add the following to the end of /etc/wpa_supplicant.conf:
network={
ssid="NetworkEssid"
scan_ssid=1 # only needed if your access point uses a hidden ssid
proto=WPA
key_mgmt=WPA-PSK
psk=945609a382413e64d57daef00eb5fab3ae228716e1e440981c004bc61dccc98c
}
(i) You may have to specify proto=WPA and key_mgmt=WPA-PSK, but wpa_supplicant can usually autodetect them correctly.
===============================================================================================
Integration with DHCP
(i) Note that the instructions below are deprecated. The changes that I made in Dapper's wpasupplicant package already take care of this case. [DanielTChen]
If you want your wireless card to aquire a new IP address using DHCP when wpa_supplicant associates with an access point, use the wpa_cli utility as documented in the wpa_supplicant README:
wpa_cli can used to run external programs whenever wpa_supplicant
connects or disconnects from a network. This can be used, e.g., to
update network configuration and/or trigget DHCP client to update IP
addresses, etc.
The wpa_cli utility can automatically execute a script whenever wpa_supplicant connects or disconnects from an access point. For this, use the -a switch like so:
wpa_cli -a<my-script>
The script will be invoked like this:
my-script $IF $CONN
Where $IF is the interface (eth0, ath0, etc), and $CONN is the event - either "CONNECTED" or "DISCONNECTED".
IconsPage/example.png
The simplest thing to do is write a script that invokes ifup or ifdown. I've put it in /sbin/wpa_action:
#! /bin/bash
IFNAME=$1
CMD=$2
if [ "$CMD" == "CONNECTED" ]; then
SSID=`wpa_cli -i$IFNAME status | grep ^ssid= | cut -f2- -d=`
logger "WiFi: Connecting `$IFNAME' to network `$SSID'"
ifup $IFNAME
elif [ "$CMD" == "DISCONNECTED" ]; then
logger "WiFi: Disconnecting `$IFNAME`"
ifdown $IFNAME
fi
Then, edit /etc/init.d/wpasupplicant to run wpa_cli appropriately. Look for these lines:
case "$1" in
start)
echo -n "Starting wpa_supplicant: "
start-stop-daemon --start --name $PNAME
--oknodo --startas $DAEMON -- -B $OPTIONS
echo "done."
;;
stop)
Insert a sleep and wpa_cli call below the start-stop-daemon call:
case "$1" in
start)
echo -n "Starting wpa_supplicant: "
start-stop-daemon --start --name $PNAME
--oknodo --startas $DAEMON -- -B $OPTIONS
sleep 1
wpa_cli -a/sbin/wpa_action -B
echo "done."
;;
stop)
If you are using DHCP exclusively to configure your wireless interface, then make sure you have this line for your wireless interface in /etc/network/interfaces:
iface eth0 inet dhcp
Where "eth0" is your wireless interface. And you'll want to make sure that your computer doesn't try to automatically start the interface up without an associated AP, so remove your wireless interface from the 'auto' line in /etc/network/interfaces:
auto lo eth0 eth1
So it becomes
auto lo eth1
Listing only those interfaces that you want to configure on startup. (Obviously, your 'auto' line will look different, depending on what network interfaces you have on your system.) Now, whenever you associate with a new wireless access point, your wireless interface will have an IP automatically configured and you'll be fully connected to the network. (YAY!)
===============================================================================================