在Ubuntu中使用360随身WiFi

##测试环境
在64位Ubuntu 12.04(内核:3.2.0)桌面环境下,使用第1代360随身WiFi测试成功!

通过以下操作,在360随身WiFi留在电脑USB接口的前提下,每次开机后手机都可以自动连接360随身WiFi生成的无线网。

再也不用担心手机的流量了!

##解决方案
* 安装依赖

1
sudo apt-get install hostapd isc-dhcp-server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash
 
function usage() {
    echo "[x] Usage: `basename $0` [360-wifi-interface] [public-network-interface] [password(optional)] "
    echo " [360-wifi-interface]: the network interface of 360-wifi, wlan0 for example."
    echo " [public-network-interface]: the network interface of public network, eth0 for example."
    echo " [password(optional)]: password of your new WIFI network (>=8 bytes). "
    exit
}
 
 
if [ $# -lt 2 ] || [ $# -gt 3 ] ; then
usage
fi
 
key=$(echo $RANDOM)$(echo $RANDOM)
 
if [ $# -eq 3 ]; then
key=$3
fi
 
if [ ${#key} -lt 8 ]; then
echo "[x] The length of password can not be less than 8."
    exit
fi
 
 
in_interface=$1
out_interface=$2
 
WIFI_HOME=~/.360wifi
 
 
#[1] Check whether we have 360 wifi inserted
 
echo "[*] Checking 360-wifi ... "
result=$(lsusb | grep -e "148f:5370 Ralink Technology")
 
if [ $? -ne 0 ]; then
echo "[x] Please insert 360-wifi into the USB interface"
    exit
fi
 
#[2] check whether kernel has CONFIG_RT2800USB_RT53XX configuration
#CONFIG_RT2800USB_RT53XX=y
echo "[*] Checking kernel version ... "
 
kernel_version=$(uname -r)
# echo $kernel_version
 
result=$(cat /boot/config-$kernel_version | grep -e "CONFIG_RT2800USB_RT53XX=y")
 
if [ $? -ne 0 ]; then
echo "[x] Sorry, your kernel version is not currently supported"
    exit
fi
 
 
# [3] install necessary packages
echo "[*] Installing necessary packages ... "
echo " -->[a] hostapd"
sudo apt-get install hostapd > /dev/null
 
echo " -->[b] isc-dhcp-server"
sudo apt-get install isc-dhcp-server > /dev/null
 
 
# [4] set isc-dhcp-server
echo "[*] Setting isc-dhcp-server ... "
if [ -f /etc/dhcp/dhcpd.$in_interface.conf ]; then
sudo rm /etc/dhcp/dhcpd.$in_interface.conf
fi
 
echo "default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet 10.1.1.0 netmask 255.255.255.0 {
range 10.1.1.100 10.1.1.200;
option domain-name-servers 8.8.8.8;
option routers 10.1.1.1;
default-lease-time 600;
max-lease-time 7200;
}" | sudo tee /etc/dhcp/dhcpd.$in_interface.conf > /dev/null
sudo ifconfig $in_interface 10.1.1.1 up
sudo dhcpd -q -cf /etc/dhcp/dhcpd.$in_interface.conf -pf /var/run/dhcp-server/dhcpd.pid $in_interface
 
 
echo "[*] Setting iptable ... "
forward=$(cat /proc/sys/net/ipv4/ip_forward)
if [ $forward -eq "0" ]; then
echo " -->[*] Enabling ipv4 forwarding"
    echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
fi
echo " -->[*] Setting iptables rules"
sudo iptables -F
sudo iptables -t nat -F
sudo iptables -t nat -A POSTROUTING -s 10.1.1.0/24 -o $out_interface -j MASQUERADE
sudo iptables -A FORWARD -s 10.1.1.0/24 -o $out_interface -j ACCEPT
sudo iptables -A FORWARD -d 10.1.1.0/24 -m conntrack --ctstate ESTABLISHED,RELATED -i $out_interface -j ACCEPT
 
echo "[*] Setting hostapd ... "
 
#ssid=360_FREE_WIFI$RANDOM
ssid=360_FREE_WIFI
 
echo
echo "**** SSID : $ssid, key: $key. Enjoy! ****"
echo
function clean_up {
    echo "[*] Cleaning up ..."
    if [ -f /var/run/dhcp-server/dhcpd.pid ]; then
dhcpd_pid=$(cat /var/run/dhcp-server/dhcpd.pid)
        sudo kill -9 $dhcpd_pid > /dev/null
        # echo $dhcpd_pid
    fi
}
 
trap 'clean_up;echo "Goodbye"' SIGINT SIGTERM SIGQUIT SIGKILL
 
if [ ! -d $WIFI_HOME ]; then
mkdir $WIFI_HOME
fi
 
if [ -f $WIFI_HOME/.hostapd.$in_interface.conf ]; then
rm $WIFI_HOME/.hostapd.$in_interface.conf
fi
 
echo "interface=$in_interface
driver=nl80211
ssid=$ssid
hw_mode=g
channel=1
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=3
wpa_passphrase=$key
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP" | tee $WIFI_HOME/.hostapd.$in_interface.conf > /dev/null
 
# sudo hostapd $WIFI_HOME/.hostapd.$in_interface.conf -P $WIFI_HOME/.hostapd.$in_interface.pid -B
sudo hostapd $WIFI_HOME/.hostapd.$in_interface.conf > /dev/null
  • 开机启动

把上述脚本命名为360wifi.sh,添加可执行权限后放在家目录下。修改/etc/rc.local,在exit 0之前添加如下一行:

1
nohup ~/360wifi.sh wlan1 eth0 12345678 &

注意:根据实际情况修改命令中的参数!

##参考资料:

  1. 错误,求助lee@lee-System-Product-Name:~$ ./ubuntu.sh wlan0 eth0 123456789[*] Checking 360-wifi … [*] Checking kernel version … [*] Installing necessary packages … –> hostapd[sudo] password for lee: –> isc-dhcp-server[*] Setting isc-dhcp-server … !are you sure you have connected to internet.9.1: 未知的服务器错误ifconfig: `–help’ 给出使用信息。[*] Setting iptable … –>[*] Setting iptables rulesiptables v1.4.21: host/network `.9.0′ not foundTry `iptables -h’ or ‘iptables –help’ for more information.iptables v1.4.21: host/network `.9.0′ not foundTry `iptables -h’ or ‘iptables –help’ for more information.iptables v1.4.21: host/network `.9.0′ not foundTry `iptables -h’ or ‘iptables –help’ for more information.[*] Setting hostapd … **** SSID : 360_FREE_WIFI16767, key: 123456789. Enjoy! ****lee@lee-System-Product-Name:~$

    • 命令行中wlan0,eth0要根据电脑的配置进行修改的,还有看看iptables的参数是不是需要修改一下。