diff options
author | ache <ache@ache.one> | 2018-01-15 04:26:28 +0100 |
---|---|---|
committer | ache <ache@ache.one> | 2018-01-15 04:26:28 +0100 |
commit | f2425a654eabd9961b5948b42185d7cdb541fe57 (patch) | |
tree | 19fd7e6eafed88f6116df94338b8246e2bd9d6d1 /coWifi.sh | |
parent | Rename DHCP (diff) |
Rename coWifi
Diffstat (limited to 'coWifi.sh')
-rwxr-xr-x | coWifi.sh | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/coWifi.sh b/coWifi.sh new file mode 100755 index 0000000..5e17619 --- /dev/null +++ b/coWifi.sh @@ -0,0 +1,65 @@ +#!/bin/env bash + +interface=""; + + +function guess_wifi { + toAll="$1" + _interface="" + 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 + echo "${_interface}" + exit 1 + fi + fi + echo "${_interface}" +} + + + +if [ "$1" == 'off' ] ; then + if [ -z "$2" ] ; then + interface=$(guess_wifi '') + else + interface=$(guess_wifi 'all') + fi + echo 'OFF' + sudo pkill -f dhcpcd + sudo pkill -f wpa_supplicant + if [ "${interface}" = 'all' ] ; then + sudo ip route flush all + else + sudo ip route flush dev "${interface}" + fi + sudo pkill -f ssh + exit 0 +elif [ -z "$1" ] ; then + interface=$(guess_wifi '') +else + interface="$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}" |