#!/bin/env bash interface=""; function guess_wifi { toAll="$1" for i in `ls /sys/class/net/`; do if [ -d "/sys/class/net/$i/wireless" ] ; then interface="$i" fi done if [ -z $interface ] ; then echo $'No Wireless interface found\nExit' if [ "$toAll" == "all" ] ; then echo 'flushing all' interface=all else exit 1 fi fi } echo "$@ $*" if [ "$1" == 'off' ] ; then if [ -z "$2" ] ; then interface="$2" else guess_wifi 'all' fi echo 'OFF' sudo pkill -f dhcpcd sudo pkill -f wpa_supplicant sudo ip route flush via "$interface"; sudo pkill -f ssh exit 0 elif [ -z "$1" ] ; then guess_wifi '' else "$1" fi if [ -z "$2" ] then sudo wpa_supplicant -B "-i${interface}" -D wext -c/etc/wpa_supplicant/wpa_supplicant.conf else if [ -z "$3" ] then sudo iwconfig "${interface}" essid "$2" else sudo iwconfig "${interface}" ap "$3" sudo iwconfig "${interface}" essid "$2" fi fi sudo dhcpcd "${interface}"