-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathinit_ap_web.sh
More file actions
98 lines (78 loc) · 2.11 KB
/
init_ap_web.sh
File metadata and controls
98 lines (78 loc) · 2.11 KB
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
#!/bin/sh
echo "=== 安装 AP热点 + DHCP(稳定版) ==="
# 生成基于 MAC 地址的固定 SSID ID (绝对唯一)
# 使用完整 MAC 的后 6 位,约 1680 万种可能,映射到 1-9999999
MAC_SUFFIX=$(cat /sys/class/net/wlan0/address 2>/dev/null | tr -d ':' | tail -c 6)
RANDOM_ID=$((16#${MAC_SUFFIX} % 9999999 + 1))
SSID="chenlong-robot-${RANDOM_ID}"
# 热点配置
cat > /etc/hostapd.conf <<EOF
interface=wlan0
driver=nl80211
ssid=${SSID}
hw_mode=g
channel=6
auth_algs=1
EOF
# DHCP配置 (手机必通)
cat > /etc/udhcpd.conf <<'EOF'
start 192.168.4.100
end 192.168.4.200
interface wlan0
lease 86400
opt subnet 255.255.255.0
opt router 192.168.4.1
opt dns 192.168.4.1
EOF
# 自启脚本 (延时启动,不抢系统网络)
cat > /etc/init.d/S98apstart <<'EOF'
#!/bin/sh
sleep 20
killall wpa_supplicant hostapd udhcpd 2>/dev/null
ifconfig wlan0 192.168.4.1 netmask 255.255.255.0 up
udhcpd /etc/udhcpd.conf &
hostapd -B /etc/hostapd.conf
exit 0
EOF
chmod 755 /etc/init.d/S98apstart
# 立即启动
killall wpa_supplicant hostapd udhcpd 2>/dev/null
sleep 1
ifconfig wlan0 192.168.4.1 netmask 255.255.255.0 up
udhcpd /etc/udhcpd.conf &
hostapd -B /etc/hostapd.conf
echo "✅ 热点: ${SSID}"
echo "✅ DHCP已启动"
echo "连接后访问: http://192.168.4.1"
echo "已启用wlan1 作为wifi连接网口"
#----------------------------------------------------------------------------
#!/bin/sh
BASE_DIR="/root/"
LOG_FILE="/tmp/wifi_web.log"
mkdir -p $BASE_DIR
echo "===== WiFi Web Setup Start =====" > $LOG_FILE
############################################
# 1. 创建 wlan1 (STA接口)
############################################
if ! iw dev | grep -q "wlan1"; then
echo "Creating wlan1..." >> $LOG_FILE
iw phy phy0 interface add wlan1 type managed
sleep 1
fi
cat > /etc/init.d/S99webstart <<'EOF'
#!/bin/sh
sleep 30
if ! iw dev | grep -q "wlan1"; then
echo "Creating wlan1 interface..."
ip link set wlan0 down
iw phy phy0 interface add wlan1 type managed
sleep 2
fi
ip link set wlan0 up
ip link set wlan1 up
sleep 5
chmod +x /root/AKA-00/init.sh
/root/AKA-00/init.sh
exit 0
EOF
chmod 755 /etc/init.d/S99webstart