You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/modules/auto-hotspot/filesystem/root/usr/bin/autohotspotN
+83-21Lines changed: 83 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -1,25 +1,26 @@
1
1
#!/bin/bash
2
-
#version 0.95-1-N/HS-I
2
+
#version 0.97-N/HS-I modded
3
3
# Based on tutorial http://www.raspberryconnect.com/network/item/330-raspberry-pi-auto-wifi-hotspot-switch-internet
4
4
# Part of CustomPiOS auto-hotspot module
5
5
6
6
#You may share this script on the condition a reference to RaspberryConnect.com
7
7
#must be included in copies or derivatives of this script.
8
8
9
-
#Network Wifi & Hotspot with Internet
10
-
#A script to switch between a wifi network and an Internet routed Hotspot
9
+
#Network Wifi & Hotspot with Network/Internet
10
+
#A script to switch between a wifi network and an Network/Internet routed Hotspot
11
11
#A Raspberry Pi with a network port required for Internet in hotspot mode.
12
12
#Works at startup or with a seperate timer or manually without a reboot
wifidev="wlan0"#device name to use. Default is wlan0.
17
+
ethdev="eth0"#Ethernet port to use with IP tables
17
18
#use the command: iw dev ,to see wifi interface name
18
19
19
20
IFSdef=$IFS
20
21
cnt=0
21
22
#These four lines capture the wifi networks the RPi is setup to use
22
-
wpassid=$(awk '/ssid="/{ print $0 }' /etc/wpa_supplicant/wpa_supplicant.conf | awk -F'ssid=''{ print $2 }'ORS=','| sed 's/\"/''/g'| sed 's/,$//'| sed 's/\n//g'| sed 's/\r//g')
23
+
wpassid=$(awk '/ssid="/{ print $0 }' /etc/wpa_supplicant/wpa_supplicant.conf | awk -F'ssid=''{ print $2 }'| sed 's/\r//g'| awk 'BEGIN{ORS=","} {print}'| sed 's/\"/''/g'| sed 's/,$//')
23
24
IFS=","
24
25
ssids=($wpassid)
25
26
IFS=$IFSdef#reset back to defaults
@@ -38,12 +39,24 @@ ssidsmac=("${ssids[@]}" "${mac[@]}") #combines ssid and MAC for checking
38
39
39
40
createAdHocNetwork()
40
41
{
42
+
echo"Autohotspot by RaspberryConnect.com"
43
+
echo"Creating Hotspot"
41
44
ip link set dev "$wifidev" down
42
45
ip a add 192.168.50.1/24 brd + dev "$wifidev"
43
46
ip link set dev "$wifidev" up
44
-
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
45
-
iptables -A FORWARD -i eth0 -o "$wifidev" -m state --state RELATED,ESTABLISHED -j ACCEPT
46
-
iptables -A FORWARD -i "$wifidev" -o eth0 -j ACCEPT
47
+
dhcpcd -k "$wifidev">/dev/null 2>&1
48
+
if iptables 2>&1| grep 'no command specified';then
49
+
iptables -t nat -A POSTROUTING -o "$ethdev" -j MASQUERADE
50
+
iptables -A FORWARD -i "$ethdev" -o "$wifidev" -m state --state RELATED,ESTABLISHED -j ACCEPT
51
+
iptables -A FORWARD -i "$wifidev" -o "$ethdev" -j ACCEPT
52
+
elif nft 2>&1| grep 'no command specified';then
53
+
nft add table inet ap
54
+
nft add chain inet ap rthrough { type nat hook postrouting priority 0 \; policy accept \; }
55
+
nft add rule inet ap rthrough oifname "$ethdev" masquerade
56
+
nft add chain inet ap fward { type filter hook forward priority 0 \; policy accept \; }
57
+
nft add rule inet ap fward iifname "$ethdev" oifname "$wifidev" ct state established,related accept
0 commit comments