aboutsummaryrefslogtreecommitdiffstats
path: root/viensamoi/create_ap.sh
blob: 28f595c2ef58a29280672c798d9b6e69c8f7e4e1 (plain) (blame)
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
#!/bin/bash

if [[ $# -ne 3 ]]; then
#if [[ $# -ne 4 ]]; then
    echo "usage: $0 iface ssid bssid"
    #echo "usage: $0 iface ssid bssid ip"
    exit 1
fi

IFACE=$1
SSID=$2
BSSID=$3
#IP=$4
IP=172.16.0.1 # fixed for now, keep coherent with dnsmasq.conf

sudo tmux new-session -d -s create_ap
sudo tmux select-window -t create_ap:0

echo "[+] Killing old daemons"
sudo pkill -f 'hostapd ./hostapd.conf'
sudo pkill -f 'dnsmasq -q'

echo "[+] Setting $IFACE bssid to $BSSID"
sudo ifconfig $IFACE down
sudo ifconfig $IFACE hw ether $BSSID

echo "[+] Configuring hostapd.conf"
sed -i "s/^interface=.*/interface=$IFACE/" ./hostapd.conf
sed -i "s/^ssid=.*/ssid=$SSID/" ./hostapd.conf

echo "[+] Starting hostapd"
sudo tmux split-window -h -t create_ap "sudo hostapd ./hostapd.conf"

echo "[+] Setting $IFACE IP to $IP"
sudo ifconfig $IFACE $IP up

echo "[+] Starting DHCP and DNS"
sudo tmux split-window -v -t create_ap "sudo dnsmasq -d -i $IFACE -C ./dnsmasq.conf"

echo "[+] Configuring iptables"
sudo iptables -I INPUT -i $IFACE -p udp --dport 67:68 --sport 67:68 -j ACCEPT

echo "[+] All set ! Waiting..."
sleep 1
sudo tmux select-pane -L -t create_ap
sudo tmux send-keys -t create_ap:0 "ifconfig $IFACE"
sudo tmux send-keys -t create_ap:0 "iwconfig $IFACE"
sudo tmux send-keys -t create_ap:0 "route -n"

sudo tmux attach-session -t create_ap