Last active
December 4, 2015 19:17
-
-
Save cyrus-and/74c883930b493dc21976 to your computer and use it in GitHub Desktop.
Instant Wi-Fi AP
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 -e | |
# Instant Wi-Fi AP | |
# | |
# Dependencies: sudo apt-get install macchanger hostapd | |
if [ "$#" != '3' ]; then | |
echo 'Usage: <SSID> <channel> <passphrase>' 1>&2 | |
exit 1 | |
fi | |
SSID="$1" | |
CHANNEL="$2" | |
PASSPHRASE="$3" | |
BRIDGE_IFACE=br0 | |
MAIN_IFACE=eth0 | |
WIFI_IFACE=wlan0 | |
HOSTAPD_CONF=" | |
interface=$WIFI_IFACE | |
bridge=$BRIDGE_IFACE | |
ssid=$SSID | |
channel=$CHANNEL | |
wpa=3 # 0b11 | |
wpa_passphrase=$PASSPHRASE | |
wpa_key_mgmt=WPA-PSK | |
wpa_pairwise=CCMP TKIP | |
rsn_pairwise=CCMP | |
" | |
log() { | |
printf '\e[35m[+] \e[32m%s\e[0m\n' "$1" | |
} | |
setup() { | |
log 'Spoofing the AP address' | |
macchanger -r "$WIFI_IFACE" | |
log 'Setting up the bridge' | |
ip link add "$BRIDGE_IFACE" type bridge | |
ip link set "$BRIDGE_IFACE" up | |
ip link set "$MAIN_IFACE" master "$BRIDGE_IFACE" | |
} | |
cleanup() { | |
log 'Removing the bridge' | |
ip link delete "$BRIDGE_IFACE" | |
ip link set "$MAIN_IFACE" nomaster | |
log 'Bye!' | |
} | |
run() { | |
log 'Starting the AP' | |
hostapd 2>&1 <(echo "$HOSTAPD_CONF") | |
} | |
trap cleanup EXIT | |
setup | |
run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment