Chinaunix首页 | 论坛 | 博客
  • 博客访问: 565230
  • 博文数量: 127
  • 博客积分: 1169
  • 博客等级: 少尉
  • 技术积分: 1298
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-16 14:29
个人简介

空白

文章分类

全部博文(127)

分类: LINUX

2017-02-23 17:23:32

问题:系统的网络配置文件为/mnt/config/network.xml; 内容如下:
  1. <?xml version="1.0" encoding="gb18030" standalone="no" ?>
  2. <HHProtocol>
  3.     <network>
  4.         <state>2</state>
  5.         <prevState>0</prevState>
  6.         <dns1>223.5.5.5</dns1>
  7.         <dns2>223.5.5.5</dns2>
  8.         <ethIp>192.168.1.32</ethIp>
  9.         <ethNetmask>255.255.255.0</ethNetmask>
  10.         <ethGateway>192.168.1.1</ethGateway>
  11.         <ethMac></ethMac>
  12.         <WifiIp>192.168.1.101</WifiIp>
  13.         <WifiNetmask>255.255.255.0</WifiNetmask>
  14.         <WifiGateway>192.168.1.1</WifiGateway>
  15.         <WifiMac></WifiMac>
  16.         <WifiSsid>KYiHua</WifiSsid>
  17.         <WifiPasswd>k6688</WifiPasswd>
  18.     </network>
  19. </HHProtocol>
如何获取<state>标签的值?
解决方法:
  1. NETWORK_CFG_FILE="/mnt/config/network.xml"
  2. if [ -f $NETWORK_CFG_FILE ]; then
  3.         NETWORK_STATE=`sed -n 's/.*>\(.*\)<\/state>/\1/p' $NETWORK_CFG_FILE`
  4.         echo $NETWORK_STATE
  5.         if [ "$NETWORK_STATE" == "0" ]; then
  6.                 echo "wifi ap mode"
  7.                 insmod rtutil5370ap.ko
  8.                 insmod rt5370ap.ko
  9.                 insmod rtnet5370ap.ko
  10.                 ifconfig ra0 192.168.8.1
  11.                 /sbin/udhcpd -fS /etc/udhcpd.conf &
  12.         elif [[ "$NETWORK_STATE" == "3" || "$NETWORK_STATE" == "4" ]]; then
  13.                 echo "wifi sta mode!"
  14.                 insmod rtutil5370sta.ko
  15.                 insmod rt5370sta.ko
  16.                 insmod rtnet5370sta.ko
  17.                 /usr/local/bin/wpa_supplicant -B -Dwext -ira0 -c/etc/wpa_supplic
  18.                 #ifconfig ra0 up
  19.         else
  20.                 echo "ethernet mode"
  21.                 ifconfig eth0 up
  22.         fi
  23. else
  24.         echo "network cfg xml not exist, ethernet mode"
  25.         ifconfig eth0 up
  26. fi
阅读(3221) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~