aboutsummaryrefslogblamecommitdiffstats
path: root/viensamoi/create_ap.sh
blob: 28f595c2ef58a29280672c798d9b6e69c8f7e4e1 (plain) (tree)

















































                                                                                    
#!/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