[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: 自动连接无线网络的代码



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


不知道为啥,whiptail在我这里运行不正常。
还有,我自己测试出了一个bug。

essid_in_list=$(echo $wnet_list | grep $essid)
test -n "$essid_in_list" && target_net=$iface; break
这里$essid_in_list当没有匹配的时候,会变成一个回车,造成无论是什么网络
状况,都是启用头个网络。
应该写成这样。
if echo $wnet_list | grep $essid > /dev/null; then
target_net=$iface
break
fi


swhe 写道:
> 为什么不用whiptail代替zenity,呵呵
>
> On 10/27/07, shell909090 <shell909090@gmail.com> wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> 最近我写了一个自动处理无线网络的代码,大家看看有没有bug,有没有更简单
>> 的方法(当然不是指用network-manage这种)。
>> 处理流程是这样的。
>> 先关闭无线连接,然后看参数。
>> 如果是scannet的,扫描当前网络状态。让用户挑一个想要的网络,输入密码,
>> 然后dhcp。
>> 如果是interface的,从/etc/network/interface里面找出配置列表。让用户挑
>> 一个,启用。
>> 如果是autoiface的,从/etc/network/interface里面找出配置列表。依次扫描
>> essid是否存在,存在的,启用。
>> 其余的,参数当作/etc/network/interface里面的配置名称,启用。
>>
>> - ----------------------------------------
>> #! /bin/bash
>>
>> function scannet (){
>> ifconfig ath0 up
>> wnet_list=$(iwlist ath0 scan | grep "ESSID" | sed
>> 's/.*ESSID:"\(.*\)"/\1/')
>> target_net=$(zenity --list --column="Access Point" $wnet_list)
>> test -z "$target_net" && exit 0
>> net_pass=$(zenity --entry --hide-text --title=password --text="")
>> iwconfig ath0 essid "$target_net" key s:"$net_pass"
>> dhclient3 ath0
>> }
>>
>> function autoiface (){
>> ifconfig ath0 up
>> wnet_list=$(iwlist ath0 scan | grep "ESSID" | sed
>> 's/.*ESSID:"\(.*\)"/\1/')
>> iface_list=$(grep "iface w" /etc/network/interfaces | sed 's/iface
>> \(.*\) inet/\1/')
>> ifconfig ath0 down
>> for iface in $iface_list
>> do
>> line=$(grep -n -m1 "iface $iface" /etc/network/interfaces | cut
>> - -f1 -d:)
>> essid=$(cat /etc/network/interfaces | tail -n +$line | grep -m 1
>> "wireless-essid" | sed "s/.*wireless-essid\\s*\(.*\)/\1/")
>> essid_in_list=$(echo $wnet_list | grep $essid)
>> test -n "$essid_in_list" && target_net=$iface; break
>> done
>> }
>>
>> ifstatus=$(cat /etc/network/run/ifstate | grep ath0 | sed "s/ath0=//")
>> if [ -n "$ifstatus" ]; then
>> echo -n "ifdown $ifstatus..."
>> /sbin/ifdown ath0
>> echo "done"
>> else
>> ifconfig ath0 down
>> fi
>>
>> case "$1" in
>> "scannet")
>> scannet
>> exit 0
>> ;;
>> "interface")
>> iface_list=$(grep "iface w" /etc/network/interfaces | sed 's/iface
>> \(.*\) inet static/\1/')
>> target_net=$(zenity --list --column="Network Config" $iface_list)
>> ;;
>> "autoiface")
>> autoiface
>> ;;
>> *)
>> target_net="$1"
>> ;;
>> esac
>>
>> test -z "$target_net" && exit 0
>> echo "ifup $target_net..."
>> /sbin/ifup ath0=$target_net
>> sleep 1
>> echo "done"
>> - ----------------------------------------
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG v1.4.6 (GNU/Linux)
>> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>>
>> iD8DBQFHI03w8b9PPLS5iI4RAojYAJ9iWWHYIGvap9KAwGbL0aBlKs7ChwCglndF
>> F6zKaUyHBqh9eOEUVT946dU=
>> =97c2
>> -----END PGP SIGNATURE-----
>>
>>
>> --
>> To UNSUBSCRIBE, email to debian-chinese-gb-REQUEST@lists.debian.org
>> with a subject of "unsubscribe". Trouble? Contact
listmaster@lists.debian.org
>>
>>
>
>

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHJVmb8b9PPLS5iI4RAnV+AKDXDyWcYx83qxfQsTCcsAxTLAt1pgCffO0l
Y8cgr26fx6uXYv3edOHPBCE=
=LMFM
-----END PGP SIGNATURE-----



Reply to: