-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathset-up.sh
61 lines (48 loc) · 1.7 KB
/
set-up.sh
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
#!/bin/bash
if [ $# -ne 1 ];
then
echo -e "This will generate a hotspot with generated password for a chosen SSID. \n"
echo -e "Usage:\n$0 <SSID>";
exit 1;
fi
if [ ! $(id -u) -eq "0" ];
then
echo "Please run as root"
exit 2;
fi
# Start
# change hostapd
SSIDNAME=$1
echo -e "\e[32m(1/8) - Setting SSID to $SSIDNAME \e[39m"
sed s/SSIDHERE/$SSIDNAME/ hostapd.conf.template > hostapd.conf
# Generate New Passphase
RANDOMPASSPHRASE=$(uuidgen)
echo -e "\e[32m(2/8) - Generated random passphrase to $RANDOMPASSPHRASE \e[39m"
sed -i s/PASSPHRASEHERE/$RANDOMPASSPHRASE/ hostapd.conf
echo -e "\e[32m(3/8) - Updating /etc/hostapd/hostapd.conf \e[39m"
cp hostapd.conf /etc/hostapd/hostapd.conf
echo -e "\e[32m(4/8) - Configuring hotspot's ip and route \e[39m"
# Configure IP address for WLAN
ifconfig wlan0 192.168.150.1
# Start DHCP/DNS server
service dnsmasq restart
# Enable routing
sysctl net.ipv4.ip_forward=1
# Enable NAT
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
# Generate QR code for WIFI connection
echo -e "\e[32m(5/8) - Generating QR code to connect to \e[39m"
./generatewifiqr.sh $(cat /etc/hostapd/hostapd.conf | grep "ssid\|wpa_passphrase" | cut -d"=" -f2 | xargs)
# Run access point daemon
echo -e "\e[32m(6/8) - Running hostapd now... Use Ctrl-C to terminate hotspot \e[39m"
hostapd /etc/hostapd/hostapd.conf || (echo -e "\e[91m[!] Something went wrong... try : airmon-ng check kill \e[39m"; exit 1;)
# Stop
# Disable NAT
echo -e "\e[32m(7/8) - Resetting firewall and routes \e[39m"
iptables -D POSTROUTING -t nat -o eth0 -j MASQUERADE
# Disable routing
sysctl net.ipv4.ip_forward=0
# Disable DHCP/DNS server
echo -e "\e[32m(8/8) - Stopping services ... \e[39m"
service dnsmasq stop
service hostapd stop