summaryrefslogtreecommitdiffstats
path: root/usr/lib/autowifi
diff options
context:
space:
mode:
Diffstat (limited to 'usr/lib/autowifi')
-rw-r--r--usr/lib/autowifi/lib/iwlist55
-rw-r--r--usr/lib/autowifi/lib/network12
-rw-r--r--usr/lib/autowifi/lib/openwrt18
-rw-r--r--usr/lib/autowifi/lib/wps21
4 files changed, 106 insertions, 0 deletions
diff --git a/usr/lib/autowifi/lib/iwlist b/usr/lib/autowifi/lib/iwlist
new file mode 100644
index 00000000..a9f77f0c
--- /dev/null
+++ b/usr/lib/autowifi/lib/iwlist
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+print_iwlist_env(){
+ # takes environment:
+ # count
+ # MAC
+ # CHANNEL
+ # QUALITY
+ # ENCRYPTION
+ # ESSID
+ # WPA
+ # WPA2
+ for i in ESSID MAC CHANNEL QUALITY ENCRYPTION WPA WPA2;do
+ eval echo ${i}_${count}=\$${i}
+ done
+}
+
+iwlist_scan(){
+ # usage: iwlist_scan $wifi-itf
+ ifconfig $wifi up
+
+ count=0
+
+ iwlist ${1:-} scan 2>/dev/null | ( while read line;
+ do
+ case "$line" in
+ *"Cell "*)
+ [ $count -eq 0 ] || print_iwlist_env
+ WPA=0
+ WPA2=0
+ : $((count+=1))
+ MAC="${line#*Address: }"
+ ;;
+ *Channel:*)
+ CHANNEL="${line#*:}"
+ ;;
+ *Quality=*)
+ QUALITY="`printf '%s' ${line#*Quality=} | cut -d/ -f 1`"
+ ;;
+ *"Encryption key:"*)
+ ENCRYPTION="${line#*key:}"
+ ;;
+ *ESSID:*)
+ ESSID="${line#*ESSID:}"
+ ;;
+ *"IE: IEEE 802.11i/WPA2"*)
+ WPA2=1
+ ;;
+ *"IE: WPA Version 1"*)
+ WPA=1
+ ;;
+ *);;
+ esac
+ done; print_iwlist_env ;echo WIFI_COUNT=$count)
+}
diff --git a/usr/lib/autowifi/lib/network b/usr/lib/autowifi/lib/network
new file mode 100644
index 00000000..fd2eb6a9
--- /dev/null
+++ b/usr/lib/autowifi/lib/network
@@ -0,0 +1,12 @@
+#!/bin/sh
+check_gateway(){
+ ping -c 1 -w 5 $(ip route | awk '/default/{print $3}')
+}
+check_internet(){
+ secret=$(wget -O- http://euer.krebsco.de/secret)
+ if [ "$secret" == "1337" ]; then
+ return 0
+ else
+ return 1
+ fi
+}
diff --git a/usr/lib/autowifi/lib/openwrt b/usr/lib/autowifi/lib/openwrt
new file mode 100644
index 00000000..3483c1fe
--- /dev/null
+++ b/usr/lib/autowifi/lib/openwrt
@@ -0,0 +1,18 @@
+#!/bin/sh
+connect_wifi(){
+ # channel ssid encryption key
+ uci set wireless.${iface}.mode=sta
+
+ ifconfig $wifi up
+ uci set wireless.${radio}.channel=$1
+ uci set "wireless.${iface}.ssid=$2"
+ if [ $3 == "none" ] ; then
+ uci set wireless.${iface}.encryption=none
+ uci -q delete wireless.${iface}.key
+ else
+ uci set "wireless.${iface}.key=$4"
+ uci set wireless.${iface}.encryption=$3
+ fi
+ uci commit wireless
+ wifi up
+}
diff --git a/usr/lib/autowifi/lib/wps b/usr/lib/autowifi/lib/wps
new file mode 100644
index 00000000..0fdba0f5
--- /dev/null
+++ b/usr/lib/autowifi/lib/wps
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+try_wps_pin(){
+ #
+ # ESSID MAC CHANNEL ENC WPA WPA2 PIN
+ #set -ef
+ ESSID="$1"
+ MAC="$2"
+ CHANNEL="$3"
+ ENC="$4"
+ WPA="$5"
+ WPA2="$6"
+ PIN="$7"
+
+ [ "$ENC" == off ] && return 2
+
+ airmon-ng start ${WIFI:-wlan0} $CHANNEL
+ sleep 1
+ reaver -i mon0 -b $MAC -vv -p "$PIN" -f -c $CHANNEL || :
+ airmon-ng stop mon0
+}