Created
July 4, 2014 22:52
-
-
Save Demontager/bae950dd4da2a2bf33e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
HOSTAPD_CONF="/etc/hostapd_ap.conf" | |
DNSMASQ_CONF="/etc/dnsmasq.d/ap-hotspot.rules" | |
GW_IP="192.168.150.1" | |
HOSTAPD_LOG="/tmp/hostapd.log" | |
WLAN="wlan0" | |
start() { | |
service hostapd stop; service dnsmasq stop | |
echo -n "1. Enter wifi iface to start AP: " | |
read iface | |
echo -n "2. Enter AP name: " | |
read ssid | |
cat > $HOSTAPD_CONF <<EOF | |
# WiFi Hotspot | |
interface=$iface | |
driver=nl80211 | |
#Access Point | |
ssid=$ssid | |
hw_mode=g | |
# WiFi Channel: | |
channel=1 | |
macaddr_acl=0 | |
auth_algs=1 | |
ignore_broadcast_ssid=0 | |
EOF | |
if [[ ! $(grep "Bind to only one interface" "$DNSMASQ_CONF") ]]; then | |
cat <<EOF | tee "$DNSMASQ_CONF" | |
# Bind to only one interface | |
bind-interfaces | |
# Choose interface for binding | |
interface=$iface | |
# Specify range of IP addresses for DHCP leasses | |
dhcp-range=192.168.150.2,192.168.150.10,12h | |
EOF | |
chmod +x "$DNSMASQ_CONF" | |
fi | |
ifconfig "$iface" "$GW_IP" | |
service hostapd stop | |
service dnsmasq stop | |
service dnsmasq restart | |
hostapd -B "$HOSTAPD_CONF" -f "$HOSTAPD_LOG" | |
iptables -F -t nat | |
iptables -t nat -A PREROUTING -p tcp -m multiport --destination-port 8080,80,443 -j DNAT --to-destination $GW_IP:80 | |
} | |
stop() { | |
service hostapd stop; service dnsmasq stop; killall hostapd; sleep 2; killall hostapd | |
iptables -F -t nat | |
ifconfig "mon.$WLAN" down | |
ifconfig "$WLAN" down | |
ifconfig "$WLAN" up | |
} | |
msg() { | |
echo "No such option: use start/stop" | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
*) | |
msg | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment