Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 21 Oct 2017, 21:18
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Multi-Wifi-Interface scan and connect "Wifi-Scanner-2" beta
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 2 [23 Posts]   Goto page: 1, 2 Next
Author Message
stemsee

Joined: 27 Jun 2013
Posts: 1980
Location: In The Way

PostPosted: Sat 25 Mar 2017, 14:25    Post subject:  Multi-Wifi-Interface scan and connect "Wifi-Scanner-2" beta
Subject description: SOLVED!
 

I am trying to code this script which should handle up to 6 wifi-cards (scaleale). I have it detecting cards and scanning with them and displaying results in tabs in a yad pane. I can select an AP from any tab and connect to the AP using the same card that scanned it. The problem then is that I want to prevent that card/interface from being used as the scanning on the other cards continue. I came up with some code that eliminates the used interface from the yad gui but it gets disconnected at the next scan loop.


Here is the entire script thus far. If anyone can point out how to improve the code would be great!

Code:
#!/bin/sh
#Wifi-Scanner-2 by stemsee copyright (c) 2017
res=`xrandr | cut -f8,9,10 -d' ' | cut -f1 -d',' | head -1 | sed 's/ //g'`
XX=`echo $res | cut -f1 -d'x'`
YY=`echo $res | cut -f2 -d'x'`
pos="+$((XX - 640))+$((YY - YY + 20))"

depsfn () { # check dependencies
   dhclu=`which udhcpc`
   dhclu=`echo $dhclu | rev | cut -f1 -d'/' | rev`
   dhcld=`which dhcpcd`
   dhcld=`echo $dhcld | rev | cut -f1 -d'/' | rev`
   if [ -z "$dhcld" ]; then
      dhl1="udhcpc -A 8 -p /var/run/udhcpc.pid -s /etc/udhcpc.script -i"
      dhl2="/etc/udhcpc.script deconfig"
   elif [[ ! -z "$dhcld" ]]; then
      dhl3="dhcpcd"
      dhl1="dhcpcd"
      dhl2="dhcpcd -k"
   elif [[ -z "$dhclu" && -z "$dhcld" ]]; then
      zenity --info --text "$dhclu and $dhcld not found"
   fi
}
depsfn

if [[ "$1" = eth0-u ]]; then
   ifconfig $eth up
   $dhl1 $eth
   exit 0
fi
if [[ "$1" = eth0-d ]]; then
   ifconfig $eth down
   $dhl2 $eth
   exit 0
fi
if [[ "$1" = wlan0-d ]]; then
   ifconfig $int down
   $dhl2 $int
   exit 0
fi
if [[ "$1" = wlan0-u ]]; then
   ifconfig $int up
   $dhl1 $int
   exit 0
fi
if [[ "$1" = wlan1-d ]]; then
   wlanfn
   ifconfig $int down
   $dhl2 $int
   exit 0
fi
if [[ "$1" = usb0-u ]]; then
   ifconfig $usb0 up
   $dhl1 $usb0
   exit 0
fi
if [[ "$1" = usb0-d ]]; then
   ifconfig $usb0 down
   $dhl2 $usb0
   exit 0
fi

menufn () {
[[ -f /tmp/wifitray ]] && /tmp/wifitray
pics3=/usr/share/icons/oxygen/22x22/devices
pics2=/usr/share/pixmaps/puppy
pics=/usr/share/pixmaps
scanres=`iwconfig $int | grep --invert-match 'bytes'`

yad --notification --kill-parent \
    --image=/usr/share/pixmaps/wifiS.png --text="$address:
    $scanres" \
    --command="bash -c on_scanclicks" --menu="Wifi-Scanner-2!killall Wifi-Scanner-2!$pics/wirelessx.png|New-Connection!Wifi-Connect!$pics/wifi224.png|Saved Profiles!Wifi-Profiles!$pics/wireless.png|Browser!defaultbrowser!$pics/browser24.png|Re-connect Wifi!Wifi-Scanner wlan0-u!$pics/wifi124.png|Disconnect Wifi!Wifi-Scanner wlan0-d!$pics/wifi124x.png|+Scanner!Wifi-Scanner-2!$pics/wifi224.png|Stop Scanner!Wifi-Scanner wlan1-d!$pics/wifi224.png|Ethernet connect!Wifi-Scanner eth0-u!$pics3/network-wired.png|Ethernet disconnect!Wifi-Scanner eth0-d!/usr/share/icons/oxygen/22x22/devices/network-wiredx.png|Ethernet 2 connect!Wifi-Scanner eth1-u!$pics3/network-wired.png|Ethernet 2 disconnect!Wifi-Scanner eth1-d!/usr/share/icons/oxygen/22x22/devices/network-wiredx.png|Connect mobile!Wifi-Scanner usb0-u!/usr/share/icons/oxygen/22x22/devices/phone.png|Disconnect mobile!Wifi-Scanner usb0-d!/usr/share/icons/oxygen/22x22/devices/phonex.png|Close Tray!/tmp/wifitray!/usr/share/icons/oxygen/22x22/actions/application-exit.png" &
mpid=$!
task='kill $mpid'
echo "#!/bin/sh
mpid=$mpid
$task
" > /tmp/wifitray
chmod 755 /tmp/wifitray
}

startinfn () {
for tin in $int1 $int2 $int3 $int4 $int5 $int6
do
[[ /tmp/wifitray ]] && /tmp/wifitray
rm -f /tmp/wifitray
rm -f /tmp/onclick 2> /dev/null
rm -f /tmp/scans* 2> /dev/null
yad --geometry=$pos --undecorated --no-buttons --skip-taskbar --text "$mytext" --timeout 2 &
CURRENTIPS=$(ip addr show | grep $tin | grep inet | awk '{print $2}')
smooth=mytext0
ifconfig $tin up
ifconfig $tin down
/etc/udhcpc.script deconfig
for I in $CURRENTIPS; do ip addr del $I dev $tin; done 2> /dev/null
ip route flush dev $tin 2> /dev/null
rm -f /var/db/dhcpcd-${tin}.lease 2> /dev/null
rm -f /var/lib/dhcpcd/dhcpcd-${tin}.lease 2> /dev/null
rm -f /var/db/udhcpc-${tin}.lease 2> /dev/null
rm -f /var/lib/udhcpc/udhcpc-${tin}.lease 2> /dev/null
killall -9 $dhl12> /dev/null
killall -9 wpa_supplicant 2> /dev/null
rm -f /var/lib/dhcpcd/*.info 2> /dev/null
rm -f /var/run/dhcpcd*.pid 2> /dev/null
rm -f /var/lib/udhcpc/*.info 2> /dev/null
rm -f /var/run/udhcpc*.pid 2> /dev/null
rm -f /var/run/wpa_supplicant/* 2> /dev/null
rfkill unblock $tin 2>/dev/null
ifconfig $tin up
done
}
export -f startinfn
ocfn () {
if [ -z "$password" ]; then
echo "ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
update_config=1
network={
ssid=$netsel1
bssid=$address
key_mgmt=NONE
}
" > /tmp/netsel
elif [[ ! -z "$password" ]]; then
echo "ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
update_config=1
network={
ssid=$netsel1
bssid=$address
scan_ssid=1
password='$password'
#psk=$password1
key_mgmt=WPA2
pairwise=CCMP TKIP
group=CCMP TKIP
}
" > /tmp/netsel
elif [[ ! -z "$usernm" ]]; then
echo "ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
update_config=1
network={
ssid=$netsel1
bssid=$address
identity='$usernm'
password='$password'
key_mgmt=WPA-EAP
eap=PEAP
#ca_cert='/path/to/certificate'
#phase1='peaplabel=0'
phase2='auth=MSCHAPV2'
}
" > /tmp/netsel
fi
diss=`cat /tmp/netsel | grep 'ssid="' | cut -f2 -d'"'`
if [[ /root/.wifi-connect/profiles/"$diss" ]]; then
   cat /tmp/netsel > /root/.wifi-connect/profiles/"$diss"+"$address"
else
   cat /tmp/netsel > /root/.wifi-connect/profiles/"$diss"+"$address"
fi
}
ranmacfn () {
INTERFACE=$int
OUI="/opt/local/etc/oui.txt"
OUI_LEN=28000

        R=$(((RANDOM % ${OUI_LEN})+1))
        PREFIX=`head -$R $OUI | tail -1`
        CMD="ifconfig ${INTERFACE} hw ether ${PREFIX}:"
        for i in `seq 1 6`; do
            R=$(((RANDOM % 15)+1))
            C=`echo "obase=16; $R" | bc`
            CMD="$CMD$C"
            if [ $((i % 2)) = 0 ] && [ $i != 6 ]; then
                CMD="$CMD:"
            fi
        done
        RESULT=`$CMD`
          CMD=`echo $CMD | cut -f5 -d ' '`
        #echo $CMD
}

passwordfn () {
userdata=`yad --geometry=$pos --window-icon=/usr/share/pixmaps/wifi24S.png --image="/usr/share/pixmaps/wifiS.png" --title "Password for $netsel1" --form --field=name --field=Password:H --field=Confirm:H`
password=`echo $userdata | cut -f2 -d '|'`
password2=`echo $userdata | cut -f3 -d '|'`
usernm=`echo $userdata | cut -f1 -d '|'`
if [[ -z "$password2" ]]; then
   exit 0
fi
if [[ -z "$password" ]]; then
   exit 0
fi
if [[ "$password2" != "$password" ]]; then
   yad --geometry=$pos --window  --image=/usr/share/pixmaps/wifiS.png --title "Passwords don't match" --text "Try again"
   passwordfn
fi
}

function on_scanclicks() {
OLDIFCONFIG=`ifconfig | grep -e 'ESSID' -e 'bytes' -e 'bssid'|  grep --invert-match '\x00' | rev | cut -f1 -d ':' | rev | tr " " "#"`
echo -en "$OLDIFCONFIG" > /tmp/onscanclicks
TITLE="$(cat /tmp/onscanclicks 2> /dev/null)"
yad --on-top --selectable-labels --geometry "40x20-10-35" --text "$TITLE" --undecorated --no-buttons --skip-taskbar --timeout 4 &
}
export -f on_scanclicks

connectfn () {
[[ -f /tmp/wifitray ]] && /tmp/wifitray 2>/dev/null
if [ ! -z "$ONN" ]; then
   passwordfn
fi
ocfn

if [[  ! -z "$netsel1" ]]; then
   bash -c startinfn
   sleep 2
      ranmacfn
      ranmacfn
      ifconfig $int down
      ifconfig $int hw ether $CMD
      ifconfig $int up
      echo "hwaddr=$CMD" >> $HOME/.wifi-connect/wifivars      
      wpa_supplicant -Dwext -i $int -c/tmp/netsel -B
   dep=`which ifplugstatus`
   if [ -z "$dep" ]; then
      yad --geometry=$pos --undecorated --no-buttons --skip-taskbar --top --text "ifplugstatus NOT found. After connecting please install it." --timeout 4
      sleep 3
   else
      while true
      do
         state=`ifplugstatus $int | grep -e 'link beat detected'`
         if [[ ! -z "$state" ]]; then
            break
         fi
         sleep 1
      done
   fi
yad --geometry=$pos --undecorated --no-buttons --skip-taskbar --top-left --text " Requesting ip address for\n '$netsel1' " --timeout 3 &
"$dhl3" $int
   while true
   do
      ipad=`ifconfig | grep inet | sed 's/inet addr/ip/g' | grep --invert-match inet6 | grep Bcast | sed 's/         //'`
      if [[ ! -z "$ipad" ]]; then
         yad --geometry=$pos --undecorated --no-buttons --skip-taskbar --top-left --text "Ip address obtained '$ipad'" --timeout 2
      break
      fi
      sleep 1
   done
fi
menufn &
if [[ "$netsel" = "BTWifi-with-FON" ]]; then
   bt
fi
sleep 40
}
[[ -f /tmp/wifitray ]] && /tmp/wifitray 2>/dev/null
menufn
   if [[ ! -z "$netsel1" ]]; then
      unset netsel1
   fi
function scanfn (){

rm -f /tmp/interface
touch /tmp/interface
Q=1
for i in `ls /sys/class/net | sed 's/ //g' | grep --invert-match 'lo' | grep --invert-match 'usb' | grep --invert-match 'eth'`
do
echo  "int$Q=$i" >> /tmp/interface
Q=$((Q + 1))
done
. /tmp/interface
int1=$int1
int2=$int2
int3=$int3
int4=$int4
int5=$int5
int6=$int6
startinfn
if [[ ! -z "$int1"  ]]; then
these1="--tab=$int1"
else
these1=""
fi
if [[ ! -z "$int2" ]]; then
these2="--tab=$int2"
else
these2=""
fi
if [[ ! -z "$int3" ]]; then
these3="--tab=$int3"
else
these3=""
fi
if [[ ! -z "$int4" ]]; then
these4="--tab=$int4"
else
these4=""
fi
if [[ ! -z "$int5" ]]; then
these5="--tab=$int5"
else
these5=""
fi
if [[ ! -z "$int6" ]]; then
 these6="--tab=$int6"
else
these6=""
fi
if [[ ! -z "$int" ]]; then
case $int in
$int1) op1=#
these1="";;
$int2) op2=#
these2="";;
$int3) op3=#
these3="";;
$int4) op4=#
these4="";;
$int5) op5=#
these5="";;
$int6) op6=#
these6="";;
esac
fi
#yad4 --listen --window-icon=/usr/share/pixmaps/leafpad.png --geometry=400x400-80+280 --on-top --notebook --key=$$ --title="Wifi-Scanner-2: Multi-Interface-Wifi" --tab-pos=bottom $these1 $these2 $these3 $these4 $these5 $these6 --timeout 16 &
$op1 [[ ! -z "$int1" ]] &&   ecann1=`iwlist $int1 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac`
[[ ! -z "$int1" ]] &&   echo "$ecann1" | yad --plug=$$ --tabnum=1 --list --separator=';' --editable --column="$int1 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int1 | cut -f1,4 -d';' | sed 's/; /+/' | sed "s/$/+$int1+/" > /tmp/net &
$op2 [[ ! -z "$int2" ]] &&   ecann2=`iwlist $int2 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac`
 [[ ! -z "$int2" ]] &&   echo "$ecann2" | yad --plug=$$ --tabnum=2  --list --separator=';' --editable --column="$int2 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int2 | cut -f1,4 -d';' | sed 's/; /+/' | sed "s/$/+$int2+/"  > /tmp/net &
$op3 [[ ! -z "$int3" ]] &&   ecann3=`iwlist $int3 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac`
 [[ ! -z "$int3" ]] &&   echo "$ecann3" | yad --plug=$$ --tabnum=3 --list --separator=';' --editable --column="$int3 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int3 | cut -f1,4 -d';' | sed 's/; /+/' | sed "s/$/+$int3+/"  > /tmp/net &
$op4 [[ ! -z "$int4" ]] &&   ecann4=`iwlist $int4 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac`
[[ ! -z "$int4" ]] &&   echo "$ecann4" | yad --plug=$$ --tabnum=4 --list --separator=';' --editable --column="$int4 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int4 | cut -f1,4 -d';' | sed 's/; /+/' | sed "s/$/+$int4+/"  > /tmp/net &
$op5 [[ ! -z "$int5" ]] &&   ecann5=`iwlist $int5 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac`
[[ ! -z "$int5" ]] &&   echo "$ecann5" | yad --plug=$$ --tabnum=5 --list --separator=';' --editable --column="$int5 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int5 | cut -f1,4 -d';' |sed 's/; /+/' | sed "s/$/+$int5+/"  > /tmp/net &
$op6 [[ ! -z "$int6" ]] &&   ecann6=`iwlist $int6 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac`
 [[ ! -z "$int6" ]] &&   echo "$ecann6" | yad --plug=$$ --tabnum=6  --list --separator=';' --editable --column="$int6 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int6| cut -f1,4 -d';' |sed 's/; /+/' | sed "s/$/+$int6+/"  > /tmp/net &

yad4 --window-icon=/usr/share/pixmaps/leafpad.png --geometry=400x400-80+280 --on-top --notebook --key=$$ --title="Wifi-Scanner-2: Multi-Interface-Wifi" --tab-pos=bottom $these1 $these2 $these3 $these4 $these5 $these6
   ret=$?
   [[ $ret -eq 1 ]] && rm -f /tmp/{netsel,netself,net*,interface} && exit 0

   [[ -f /tmp/net ]] && netsel1=`cat /tmp/net | grep '+' | cut -f1 -d'+'`
   address=`cat /tmp/net | cut -f2 -d'+'`
   int=`cat /tmp/net | cut -f3 -d'+'`
   #export int
      if [[ ! -z "$netsel1" ]]|[[ ! -z "$address" ]]; then
         ONN=`cat /tmp/net | grep -e '~on~'`
         connectfn &
      fi
         sleep 60
         scanfn
}
export -f scanfn
scanfn
xscreenshot-20170325T182812.png
 Description   
 Filesize   46.19 KB
 Viewed   463 Time(s)

xscreenshot-20170325T182812.png


Last edited by stemsee on Sat 08 Jul 2017, 05:25; edited 3 times in total
Back to top
View user's profile Send private message MSN Messenger 
6502coder


Joined: 23 Mar 2009
Posts: 392
Location: Western United States

PostPosted: Sat 25 Mar 2017, 14:50    Post subject:  

Instead of a whole series of sed's piped together, wouldn't it be more efficient to throw all those sed edits into a single sed script? Just a thought.... Maybe you have a good reason why the entire input stream needs to be passed through each sed edit one at a time.
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 1980
Location: In The Way

PostPosted: Sat 25 Mar 2017, 17:27    Post subject:  

There's no good reason ... only ignorance!
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 1980
Location: In The Way

PostPosted: Sun 26 Mar 2017, 06:02    Post subject:  

I got it working! In a round about way!
Code:
#!/bin/sh
res=`xrandr | cut -f8,9,10 -d' ' | cut -f1 -d',' | head -1 | sed 's/ //g'`
XX=`echo $res | cut -f1 -d'x'`
YY=`echo $res | cut -f2 -d'x'`
pos="+$((XX - 640))+$((YY - YY + 20))"
rm /tmp/interface
[[ /tmp/wifitray ]] && /tmp/wifitray
rm -f /tmp/wifitray
rm -f /tmp/onclick 2> /dev/null
rm -f /tmp/scans* 2> /dev/null
interfacefn () {
for wit in `ls /sys/class/net`
do
case $wit in
   eth0|enp2s0f2) eth=$wit;;
   eth1) eths=$wit;;
   enp0s20u3|usb0) usb0=$wit;;
esac
done
}

wlanfn () {
inters=`ls /sys/class/net | sed 's/ //g' | grep --invert-match 'lo' | grep --invert-match 'usb' | grep --invert-match 'eth' | yad --window-icon=/usr/share/pixmaps/wireless.png --title="Wifi-Profi $dhclu $dhcld" --geometry=300$pos --list --separator=' ' --multiple --column="Select Interface" | tr '\n' ' '`
ret=$?
[[ $ret -eq 1 ]] && exit 0
echo "$inters"
}
wlanfn

depsfn () { # check dependencies
   dhclu=`which udhcpc`
   dhclu=`echo $dhclu | rev | cut -f1 -d'/' | rev`
   dhcld=`which dhcpcd`
   dhcld=`echo $dhcld | rev | cut -f1 -d'/' | rev`
   if [ -z "$dhcld" ]; then
      dhl1="udhcpc -A 8 -p /var/run/udhcpc.pid -s /etc/udhcpc.script -i"
      dhl2="/etc/udhcpc.script deconfig"
   elif [[ ! -z "$dhcld" ]]; then
      dhl3="dhcpcd -z"
      dhl1="dhcpcd"
      dhl2="dhcpcd -k"
   elif [[ -z "$dhclu" && -z "$dhcld" ]]; then
      zenity --info --text "$dhclu and $dhcld not found"
   fi
}
depsfn

if [[ "$1" = eth0-u ]]; then
   ifconfig $eth up
   $dhl1 $eth
   exit 0
fi
if [[ "$1" = eth0-d ]]; then
   ifconfig $eth down
   $dhl2 $eth
   exit 0
fi
if [[ "$1" = wlan0-d ]]; then
   ifconfig $int down
   $dhl2 $int
   exit 0
fi
if [[ "$1" = wlan0-u ]]; then
   ifconfig $int up
   $dhl1 $int
   exit 0
fi
if [[ "$1" = wlan1-d ]]; then
   wlanfn
   ifconfig $int down
   $dhl2 $int
   exit 0
fi
if [[ "$1" = usb0-u ]]; then
   ifconfig $usb0 up
   $dhl1 $usb0
   exit 0
fi
if [[ "$1" = usb0-d ]]; then
   ifconfig $usb0 down
   $dhl2 $usb0
   exit 0
fi

menufn () {
[[ -f /tmp/wifitray ]] && /tmp/wifitray
pics3=/usr/share/icons/oxygen/22x22/devices
pics2=/usr/share/pixmaps/puppy
pics=/usr/share/pixmaps
scanres=`iwconfig $int | grep --invert-match 'bytes'`

yad --notification --kill-parent \
    --image=/usr/share/pixmaps/wifiS.png --text="$address:
    $scanres" \
    --command="bash -c on_scanclicks" --menu="Wifi-Scanner-2!killall Wifi-Scanner-2!$pics/wirelessx.png|New-Connection!Wifi-Connect!$pics/wifi224.png|Saved Profiles!Wifi-Profiles!$pics/wireless.png|Browser!defaultbrowser!$pics/browser24.png|Re-connect Wifi!Wifi-Scanner wlan0-u!$pics/wifi124.png|Disconnect Wifi!Wifi-Scanner wlan0-d!$pics/wifi124x.png|+Scanner!Wifi-Scanner-2!$pics/wifi224.png|Stop Scanner!Wifi-Scanner wlan1-d!$pics/wifi224.png|Ethernet connect!Wifi-Scanner eth0-u!$pics3/network-wired.png|Ethernet disconnect!Wifi-Scanner eth0-d!/usr/share/icons/oxygen/22x22/devices/network-wiredx.png|Ethernet 2 connect!Wifi-Scanner eth1-u!$pics3/network-wired.png|Ethernet 2 disconnect!Wifi-Scanner eth1-d!/usr/share/icons/oxygen/22x22/devices/network-wiredx.png|Connect mobile!Wifi-Scanner usb0-u!/usr/share/icons/oxygen/22x22/devices/phone.png|Disconnect mobile!Wifi-Scanner usb0-d!/usr/share/icons/oxygen/22x22/devices/phonex.png|Close Tray!/tmp/wifitray!/usr/share/icons/oxygen/22x22/actions/application-exit.png" &
mpid=$!
task='kill $mpid'
echo "#!/bin/sh
mpid=$mpid
$task
" > /tmp/wifitray
chmod 755 /tmp/wifitray
}

startinfn () {

yad --geometry=$pos --undecorated --no-buttons --skip-taskbar --text "$Resetting $int" --timeout 2 &
CURRENTIPS=$(ip addr show | grep $tin | grep inet | awk '{print $2}')
ifconfig $tin down
for I in $CURRENTIPS; do ip addr del $I dev $tin; done 2> /dev/null
ip route flush dev $tin 2> /dev/null
rm -f /var/db/dhcpcd-${tin}.lease 2> /dev/null
rm -f /var/lib/dhcpcd/dhcpcd-${tin}.lease 2> /dev/null
rm -f /var/db/udhcpc-${tin}.lease 2> /dev/null
rm -f /var/lib/udhcpc/udhcpc-${tin}.lease 2> /dev/null
rm -f /var/run/wpa_supplicant/$int
rfkill unblock $tin 2>/dev/null
ifconfig $tin up

}

uhohfn () {
uhoh=`cat /tmp/netsel`
if [[ -z "$uhoh" ]]; then
   rm -f /tmp/netsel
   $0
   exit 0
fi
}

ocfn () {
if [ -z "$password" ]; then
echo "ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
update_config=1
network={
ssid=$netsel1
bssid=$address
key_mgmt=NONE
}
" > /tmp/netsel
elif [[ ! -z "$password" ]]; then
echo "ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
update_config=1
network={
ssid=$netsel1
bssid=$address
scan_ssid=1
password='$password'
#psk=$password1
key_mgmt=WPA2
pairwise=CCMP TKIP
group=CCMP TKIP
}
" > /tmp/netsel
elif [[ ! -z "$usernm" ]]; then
echo "ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
update_config=1
network={
ssid=$netsel1
bssid=$address
identity='$usernm'
password='$password'
key_mgmt=WPA-EAP
eap=PEAP
#ca_cert='/path/to/certificate'
#phase1='peaplabel=0'
phase2='auth=MSCHAPV2'
}
" > /tmp/netsel
fi
diss=`cat /tmp/netsel | grep 'ssid="' | cut -f2 -d'"'`
if [[ /root/.wifi-connect/profiles/"$diss" ]]; then
   cat /tmp/netsel > /root/.wifi-connect/profiles/"$diss"+"$address"
else
   cat /tmp/netsel > /root/.wifi-connect/profiles/"$diss"+"$address"
fi
}

passwordfn () {
userdata=`yad --geometry=$pos --window-icon=/usr/share/pixmaps/wifi24S.png --image="/usr/share/pixmaps/wifiS.png" --title "Password for $netsel1" --form --field=name --field=Password:H --field=Confirm:H`
password=`echo $userdata | cut -f2 -d '|'`
password2=`echo $userdata | cut -f3 -d '|'`
usernm=`echo $userdata | cut -f1 -d '|'`
if [[ -z "$password2" ]]; then
   exit 0
fi
if [[ -z "$password" ]]; then
   exit 0
fi
if [[ "$password2" != "$password" ]]; then
   yad --geometry=$pos --window  --image=/usr/share/pixmaps/wifiS.png --title "Passwords don't match" --text "Try again"
   passwordfn
fi
}

netselfn () {
userdata=`yad --geometry=620$pos --window-icon=/usr/share/pixmaps/wifi24S.png --image="/usr/share/pixmaps/wifiS.png" --title "Copy AP name and mac fields and paste here" --form --field=Essid --field=Mac Address`
id=`echo $userdata | cut -f1 -d '|' | cut -f2 -d'"'`
mad=`echo $userdata | cut -f2 -d '|' | cut -f2 -d' '`
netsel1="$id+$mad"
echo "$netsel1" > /tmp/net
}
export -f netselfn

function on_scanclicks() {
OLDIFCONFIG=`ifconfig | grep -e 'ESSID' -e 'bytes' -e 'bssid'|  grep --invert-match '\x00' | rev | cut -f1 -d ':' | rev | tr " " "#"`
echo -en "$OLDIFCONFIG" > /tmp/onscanclicks
TITLE="$(cat /tmp/onscanclicks 2> /dev/null)"
yad --on-top --selectable-labels --geometry "40x20-10-35" --text "$TITLE" --undecorated --no-buttons --skip-taskbar --timeout 4 &
}
export -f on_scanclicks

connectfn () {
[[ -f /tmp/wifitray ]] && /tmp/wifitray 2>/dev/null
if [ ! -z "$ONN" ]; then
   passwordfn
fi
ocfn
if [[  ! -z "$netsel1" ]]; then
   startinfn
   sleep 2
      ranmacfn
      ranmacfn
      ifconfig $int down
      ifconfig $int hw ether $CMD
      ifconfig $int up
      echo "hwaddr=$CMD" >> $HOME/.wifi-connect/wifivars      
      wpa_supplicant -Dwext -i $int -c/tmp/netsel -B
   dep=`which ifplugstatus`
   if [ -z "$dep" ]; then
      yad --geometry=$pos --undecorated --no-buttons --skip-taskbar --top --text "ifplugstatus NOT found. After connecting please install it." --timeout 4
      sleep 3
   else
      while true
      do
         state=`ifplugstatus $int | grep -e 'link beat detected'`
         if [[ ! -z "$state" ]]; then
            break
         fi
         sleep 1
      done
   fi
yad --geometry=$pos --undecorated --no-buttons --skip-taskbar --top-left --text " Requesting ip address for\n '$netsel1' " --timeout 3 &
$dhl3 $int
   while true
   do
      ipad=`ifconfig | grep inet | sed 's/inet addr/ip/g' | grep --invert-match inet6 | grep Bcast | sed 's/         //'`
      if [[ ! -z "$ipad" ]]; then
         yad --geometry=$pos --undecorated --no-buttons --skip-taskbar --top-left --text "Ip address obtained '$ipad'" --timeout 2
      break
      fi
      sleep 1
   done
fi
menufn &
if [ "$netsel1" = "BTWifi-with-FON" ]; then
   bt
fi
exec "$0"
}

[[ -f /tmp/wifitray ]] && /tmp/wifitray 2>/dev/null

menufn

   while [[ -z "$netsel1" ]]; do
interfacefn

   rm -f /tmp/interface
touch /tmp/interface
   Q=1
for i in  $inters
do
echo  "int$Q=$i" >> /tmp/interface
Q=$((Q + 1))
done
. /tmp/interface
int1=$int1
int2=$int2
int3=$int3
int4=$int4
int5=$int5
int6=$int6
startinfn
if [[ ! -z "$int1"  ]]; then
these1="--tab=$int1"
else
these1=""
fi
if [[ ! -z "$int2" ]]; then
these2="--tab=$int2"
else
these2=""
fi
if [[ ! -z "$int3" ]]; then
these3="--tab=$int3"
else
these3=""
fi
if [[ ! -z "$int4" ]]; then
these4="--tab=$int4"
else
these4=""
fi
if [[ ! -z "$int5" ]]; then
these5="--tab=$int5"
else
these5=""
fi
if [[ ! -z "$int6" ]]; then
 these6="--tab=$int6"
else
these6=""
fi
if [[ ! -z "$int" ]]; then
case $int in
$int1) op1=#
these1="";;
$int2) op2=#
these2="";;
$int3) op3=#
these3="";;
$int4) op4=#
these4="";;
$int5) op5=#
these5="";;
$int6) op6=#
these6="";;
esac
fi
#yad4 --listen --window-icon=/usr/share/pixmaps/leafpad.png --geometry=400x400-80+280 --on-top --notebook --key=$$ --title="Wifi-Scanner-2: Multi-Interface-Wifi" --tab-pos=bottom $these1 $these2 $these3 $these4 $these5 $these6 --timeout 16 &
$op1 [[ ! -z "$int1" ]] &&   ecann1=`iwlist $int1 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac`
[[ ! -z "$int1" ]] &&   echo "$ecann1" | yad --plug=$$ --tabnum=1 --list --separator=';' --editable --column="$int1 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int1 | cut -f1,4 -d';' | sed 's/; /+/' | sed "s/$/+$int1+/" > /tmp/net &
$op2 [[ ! -z "$int2" ]] &&   ecann2=`iwlist $int2 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac`
 [[ ! -z "$int2" ]] &&   echo "$ecann2" | yad --plug=$$ --tabnum=2  --list --separator=';' --editable --column="$int2 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int2 | cut -f1,4 -d';' | sed 's/; /+/' | sed "s/$/+$int2+/"  > /tmp/net &
$op3 [[ ! -z "$int3" ]] &&   ecann3=`iwlist $int3 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac`
 [[ ! -z "$int3" ]] &&   echo "$ecann3" | yad --plug=$$ --tabnum=3 --list --separator=';' --editable --column="$int3 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int3 | cut -f1,4 -d';' | sed 's/; /+/' | sed "s/$/+$int3+/"  > /tmp/net &
$op4 [[ ! -z "$int4" ]] &&   ecann4=`iwlist $int4 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac`
[[ ! -z "$int4" ]] &&   echo "$ecann4" | yad --plug=$$ --tabnum=4 --list --separator=';' --editable --column="$int4 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int4 | cut -f1,4 -d';' | sed 's/; /+/' | sed "s/$/+$int4+/"  > /tmp/net &
$op5 [[ ! -z "$int5" ]] &&   ecann5=`iwlist $int5 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac`
[[ ! -z "$int5" ]] &&   echo "$ecann5" | yad --plug=$$ --tabnum=5 --list --separator=';' --editable --column="$int5 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int5 | cut -f1,4 -d';' |sed 's/; /+/' | sed "s/$/+$int5+/"  > /tmp/net &
$op6 [[ ! -z "$int6" ]] &&   ecann6=`iwlist $int6 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac`
 [[ ! -z "$int6" ]] &&   echo "$ecann6" | yad --plug=$$ --tabnum=6  --list --separator=';' --editable --column="$int6 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int6| cut -f1,4 -d';' |sed 's/; /+/' | sed "s/$/+$int6+/"  > /tmp/net &

yad4 --window-icon=/usr/share/pixmaps/leafpad.png --geometry=400x400-80+280 --on-top --notebook --key=$$ --title="Wifi-Scanner-2: Multi-Interface-Wifi" --tab-pos=bottom $these1 $these2 $these3 $these4 $these5 $these6 --timeout 30
   ret=$?
   [[ $ret -eq 1 ]] && rm -f /tmp/{netsel,netself,net*,interface} && exit 0

   [[ -f /tmp/net ]] && netsel1=`cat /tmp/net | grep --invert-match 'null' | head -1 | grep '+' | cut -f1 -d'+'`
   address=`cat /tmp/net | cut -f2 -d'+'`
   int=`cat /tmp/net | cut -f3 -d'+'`
   export int
      if [[ ! -z "$netsel1" ]]|[[ ! -z "$address" ]]; then
         ONN=`cat /tmp/net | grep -e '~on~'`
         connectfn &
      fi

rm -f /tmp/net
done
Back to top
View user's profile Send private message MSN Messenger 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1368
Location: Japan

PostPosted: Sun 26 Mar 2017, 06:05    Post subject:  

6502coder wrote:
Instead of a whole series of sed's piped together, wouldn't it be more efficient to throw all those sed edits into a single sed script?
Just tried it. No grep and only one sed statement would be almost 10 times more efficient in terms of CPU usage. Also MUCH shorter.

But what is this? Are you trying to comment out code lines programmatically? Won't work
Code:
if [[ ! -z "$int" ]]; then
    case $int in
        $int1) op1=#
               these1="";;
        $int2) op2=#
               these2="";;
    esac
fi
$op1 [[ ! -z "$int1" ]] &&   ecann1=`iwlist $int1 scan | ...
     [[ ! -z "$int1" ]] &&   echo "$ecann1" | ...
$op2 [[ ! -z "$int2" ]] &&   ecann2=`iwlist $int2 scan | ...
     [[ ! -z "$int2" ]] &&   echo "$ecann2" | ...

Let's say $int equals $int1, then you want to comment out the first [[ ! -z "$int1" ]] line? Not possible. May "work" for you as expected, but for a different reason. Bash will throw an error. And what about the following line? Should not work either since it depends on the result of the (faulty) previous line.

Still much room for improvement, but this may replace above code and should work without errors:
Code:
[[ "$int" != "$int1" ]] &&   ecann1=`iwlist $int1 scan | ...
[[ "$int" != "$int1" ]] &&   echo "$ecann1" | ...
[[ "$int" != "$int2" ]] &&   ecann2=`iwlist $int2 scan | ...
[[ "$int" != "$int2" ]] &&   echo "$ecann2" | ...
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 1980
Location: In The Way

PostPosted: Mon 27 Mar 2017, 05:55    Post subject:  

MochiMoppel wrote:
6502coder wrote:
Instead of a whole series of sed's piped together, wouldn't it be more efficient to throw all those sed edits into a single sed script?
Just tried it. No grep and only one sed statement would be almost 10 times more efficient in terms of CPU usage. Also MUCH shorter.

Where is the improved statement then?

Quote:
But what is this? Are you trying to comment out code lines programmatically? Won't work

Yes, that was my intent. It didn't work also because the int1 variable got assigned a different interface anyway! Only the tabs got reassigned incorrectly with different labels but same interfaces.
Quote:

Code:
if [[ ! -z "$int" ]]; then
    case $int in
        $int1) op1=#
               these1="";;
        $int2) op2=#
               these2="";;
    esac
fi
$op1 [[ ! -z "$int1" ]] &&   ecann1=`iwlist $int1 scan | ...
     [[ ! -z "$int1" ]] &&   echo "$ecann1" | ...
$op2 [[ ! -z "$int2" ]] &&   ecann2=`iwlist $int2 scan | ...
     [[ ! -z "$int2" ]] &&   echo "$ecann2" | ...

Let's say $int equals $int1, then you want to comment out the first [[ ! -z "$int1" ]] line? Not possible. May "work" for you as expected, but for a different reason. Bash will throw an error. And what about the following line? Should not work either since it depends on the result of the (faulty) previous line.

Still much room for improvement, but this may replace above code and should work without errors:
Code:
[[ "$int" != "$int1" ]] &&   ecann1=`iwlist $int1 scan | ...
[[ "$int" != "$int1" ]] &&   echo "$ecann1" | ...
[[ "$int" != "$int2" ]] &&   ecann2=`iwlist $int2 scan | ...
[[ "$int" != "$int2" ]] &&   echo "$ecann2" | ...


I will try this!
Back to top
View user's profile Send private message MSN Messenger 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1368
Location: Japan

PostPosted: Mon 27 Mar 2017, 08:34    Post subject:  

stemsee wrote:
Where is the improved statement then?
On my USB stick.

I said that it's more efficient, I didn't say that it's more reliable. The problem is that when I run iwlist wlan0 scan the output is probably not what it should be and what you tested your code against:
Code:
# iwlist wlan0 scan
wlan0     Scan completed :
          Cell 01 - Address: 74:76:C5:73:30:FA
                    ESSID:"AirPort13306"
                    Mode:Managed
                    Frequency:2.452 GHz (Channel 9)
                    Quality:4/5  Signal level:-59 dBm  Noise level:-92 dBm
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : TKIP
                        Pairwise Ciphers (2) : TKIP CCMP
                        Authentication Suites (1) : PSK
                    IE: Unknown: DDB30050F204104A0001101044
                    IE: WPA Version 1
                        Group Cipher : TKIP
                        Pairwise Ciphers (2) : TKIP CCMP
                        Authentication Suites (1) : PSK
                    Encryption key:on
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s
                              18 Mb/s; 36 Mb/s; 54 Mb/s; 6 Mb/s; 12 Mb/s
                              24 Mb/s; 48 Mb/s

Notice the 'Quality' line. It's 'Quality:' and not 'Quality=' and there are 2 levels. Your code doesn't work here, and so does mine. Unless you provide a sample output of iwlist and state exactly what result you expect after your sed statement it makes no sense for me to post any code. Anyway my sed statement would be different from yours. Instead of deleting all the stuff that I'm not interested in I would match only the stuff that I need and ignore the rest. Makes a shorter statement but needs a bit of regex voodoo. If you are not comfortable with it you'd better try yourself with the tools and ways you can safely manage.
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 1980
Location: In The Way

PostPosted: Mon 27 Mar 2017, 17:12    Post subject:  

Thanks for that MochiMoppel

Here is a sample output of iwlist scan on my machine

Code:
iwlist wlan0 scan
wlan0     Scan completed :
          Cell 01 - Address: 32:8A:AE:8C:5E:7E
                    Channel:1
                    Frequency:2.412 GHz (Channel 1)
                    Quality=31/70  Signal level=-79 dBm 
                    Encryption key:off
                    ESSID:"BTWifi-with-FON"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
                              9 Mb/s; 12 Mb/s; 18 Mb/s
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
                    Mode:Master
                    Extra:tsf=0000010a626c371f
                    Extra: Last beacon: 63ms ago
                    IE: Unknown: 000F4254576966692D776974682D464F4E
                    IE: Unknown: 010882848B960C121824
                    IE: Unknown: 030101
                    IE: Unknown: 0706474220010D14
                    IE: Unknown: 2A0100
                    IE: Unknown: 32043048606C
                    IE: Unknown: 2D1AAC011BFFFF000000000000000000008000000000000000000000
                    IE: Unknown: 3D1601080400000000000000000000000000000000000000
                    IE: Unknown: 4A0E14000A002C01C800140005001900
                    IE: Unknown: 7F080100000000000040
                    IE: Unknown: DD180050F2020101800003A4000027A4000042435E0062322F00
                    IE: Unknown: DD0900037F01010000FF7F
          Cell 02 - Address: 52:8A:AE:8C:5E:7E
                    Channel:1
                    Frequency:2.412 GHz (Channel 1)
                    Quality=35/70  Signal level=-75 dBm 
                    Encryption key:on
                    ESSID:"BTWifi-X"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
                              9 Mb/s; 12 Mb/s; 18 Mb/s
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
                    Mode:Master
                    Extra:tsf=0000010a626bdbb4
                    Extra: Last beacon: 63ms ago
                    IE: Unknown: 00084254576966692D58
                    IE: Unknown: 010882848B960C121824
                    IE: Unknown: 030101
                    IE: Unknown: 0706474220010D14
                    IE: Unknown: 2A0100
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : TKIP
                        Pairwise Ciphers (2) : CCMP TKIP
                        Authentication Suites (1) : 802.1x
                       Preauthentication Supported
                    IE: Unknown: 32043048606C
                    IE: Unknown: 2D1AAC011BFFFF000000000000000000008000000000000000000000
                    IE: Unknown: 3D1601080400000000000000000000000000000000000000
                    IE: Unknown: 4A0E14000A002C01C800140005001900
                    IE: Unknown: 7F080100000000000040
                    IE: WPA Version 1
                        Group Cipher : TKIP
                        Pairwise Ciphers (2) : CCMP TKIP
                        Authentication Suites (1) : 802.1x
                    IE: Unknown: DD180050F2020101800003A4000027A4000042435E0062322F00
                    IE: Unknown: DD0900037F01010000FF7F
          Cell 03 - Address: A4:2B:8C:16:E2:B9
                    Channel:1
                    Frequency:2.412 GHz (Channel 1)
                    Quality=41/70  Signal level=-69 dBm 
                    Encryption key:on
                    ESSID:"BTHub5-6HRQ_EXT"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s
                              18 Mb/s; 36 Mb/s; 54 Mb/s
                    Bit Rates:6 Mb/s; 12 Mb/s; 24 Mb/s; 48 Mb/s
                    Mode:Master
                    Extra:tsf=000000289c0bad23
                    Extra: Last beacon: 63ms ago
                    IE: Unknown: 000F4254487562352D364852515F455854
                    IE: Unknown: 010882848B961224486C
                    IE: Unknown: 030101
                    IE: Unknown: 2A0100
                    IE: Unknown: 32040C183060
                    IE: Unknown: 2D1AEC0117FFFF000000000000000000000000000000000000000000
                    IE: Unknown: 3D1601000400000000000000000000000000000000000000
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK
                    IE: Unknown: DD180050F2020101000003A4000027A4000042435E0062322F00
                    IE: Unknown: 0B05020016127A
                    IE: Unknown: 7F0101
                    IE: Unknown: DD07000C4303000000
                    IE: Unknown: 0706444520010D10
                    IE: Unknown:
longline [....]
          Cell 04 - Address: 00:8A:AE:8C:5E:7E
                    Channel:1
                    Frequency:2.412 GHz (Channel 1)
                    Quality=29/70  Signal level=-81 dBm 
                    Encryption key:on
                    ESSID:"BTHub5-7PK2"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 6 Mb/s
                              9 Mb/s; 12 Mb/s; 18 Mb/s
                    Bit Rates:24 Mb/s; 36 Mb/s; 48 Mb/s; 54 Mb/s
                    Mode:Master
                    Extra:tsf=0000010a626afd65
                    Extra: Last beacon: 63ms ago
                    IE: Unknown: 000B4254487562352D37504B32
                    IE: Unknown: 010882848B960C121824
                    IE: Unknown: 030101
                    IE: Unknown: 0706474220010D14
                    IE: Unknown: 2A0100
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK
                    IE: Unknown: 32043048606C
                    IE: Unknown: 2D1AAC011BFFFF000000000000000000008000000000000000000000
                    IE: Unknown: 3D1601080400000000000000000000000000000000000000
                    IE: Unknown: 4A0E14000A002C01C800140005001900
                    IE: Unknown: 7F080100000000000040
                    IE: Unknown: DD180050F2020101800003A4000027A4000042435E0062322F00
                    IE: Unknown: DD0900037F01010000FF7F
                    IE: Unknown:
long line [....]


All I need to glean from the info is , Mac Address **:**:**:**:**:**; ESSID:"SomeName"; Encryption key: on or off; Signal Strength 29/70 Quality: -87 dBm (possibly frequency 2.4ghz Channel: 1)

for each AP found, from each card. Only need the data not the labels! IFS=" " e.g.
Code:
"BTWifi-with-Fon" **:**:**:**:** on 29/70 -87 2.4 1


cheers
stemsee

Last edited by stemsee on Thu 30 Mar 2017, 17:32; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 1980
Location: In The Way

PostPosted: Mon 27 Mar 2017, 19:22    Post subject:  

So I came up with code to list selected interfaces, then when connected, remove connected from that list for the continued scan loop using the other interfaces. Mostly working as well as any other connection tool I have used. Also admin mode, CLI, usage can change card mode and also update interfaces each loop, facilitating plug'n'play on the fly! Tested using once pci card and three usb cards; BCM (pci), ralink, Atheros, Ralink on a laptop.

Code:
Wifi-Connect-2 admin managed


Can select one or many interfaces!

Can use dhcpcd or udhcpc.

Connects with both ESSID and Mac address. Stores profiles likewise.

To do: change selection output to individual files to enable multi AP selections and connect each interface to one of its found APs, simultaneously! (Because why not!)

Also add harvesting mode to simply store AP by ESSID and MAC from each card.
Code:
#!/bin/sh
# Wifi-Scanner-2 scaleable multi-wifi-adapter scanning and connection tool
# by stemsee copyright (c) 2017
#
res=`xrandr | cut -f8,9,10 -d' ' | cut -f1 -d',' | head -1 | sed 's/ //g'`
XX=`echo $res | cut -f1 -d'x'`
YY=`echo $res | cut -f2 -d'x'`
pos="+$((XX - 640))+$((YY - YY + 20))"
rm /tmp/interfaces
[[ /tmp/wifitray ]] && /tmp/wifitray
rm -f /tmp/wifitray
rm -f /tmp/onclick 2> /dev/null
rm -f /tmp/scans* 2> /dev/null

interfacefn () {
for wit in `ls /sys/class/net`
do
case $wit in
   eth0|enp2s*) eth=$wit;;
   eth1) eths=$wit;;
   enp0s*|usb0) usb0=$wit;;
esac
done
}
interfacefn
wlanfn () {
rm -f /tmp/interface
touch /tmp/interface
if [[ -z "$1" ]]; then
inters=`ls /sys/class/net | sed 's/ //g' | grep --invert-match 'lo' | grep --invert-match 'usb' | grep --invert-match 'eth' | yad --window-icon=/usr/share/pixmaps/wireless.png --title="Wifi-Profi $dhclu $dhcld" --geometry=300$pos --list --separator=' ' --multiple --column="Select Interface" | tr '\n' ' '`
ret=$?
[[ $ret -eq 1 ]] && exit 0
echo "$inters"
Q=1
for i in  $inters
do
   ifconfig $i down
   sleep 1
   ifconfig $i up
   sleep 1
   echo  "int$Q=$i" >> /tmp/interfaces
   Q=$((Q + 1))
done
cp -f /tmp/interfaces /tmp/interface
fi
}
wlanfn

ranmacfn () {
INTERFACE=$int
OUI="/opt/local/etc/oui.txt"
OUI_LEN=28000

        R=$(((RANDOM % ${OUI_LEN})+1))
        PREFIX=`head -$R $OUI | tail -1`
        CMD="ifconfig ${INTERFACE} hw ether ${PREFIX}:"
        for i in `seq 1 6`; do
            R=$(((RANDOM % 15)+1))
            C=`echo "obase=16; $R" | bc`
            CMD="$CMD$C"
            if [ $((i % 2)) = 0 ] && [ $i != 6 ]; then
                CMD="$CMD:"
            fi
        done
        RESULT=`$CMD`
          CMD=`echo $CMD | cut -f5 -d ' '`
}

depsfn () { # check dependencies
   dhclu=`busybox which udhcpc`
   dhclu=`echo $dhclu | rev | cut -f1 -d'/' | rev`
   dhcld=`busybox which dhcpcd`
   dhcld=`echo $dhcld | rev | cut -f1 -d'/' | rev`
   if [ -z "$dhcld" ]; then
      dhl1="udhcpc -A 8 -p /var/run/udhcpc.pid -s /etc/udhcpc.script -i"
      dhl2="/etc/udhcpc.script deconfig"
   elif [[ ! -z "$dhcld" ]]; then
      dhl3="dhcpcd -z"
      dhl1="dhcpcd"
      dhl2="dhcpcd -k"
   elif [[ -z "$dhclu" && -z "$dhcld" ]]; then
      zenity --info --text "$dhclu and $dhcld not found"
   fi
}
depsfn

if [[ "$1" = eth0-u ]]; then
   ifconfig $eth up
   $dhl1 $eth
   exit 0
fi
if [[ "$1" = eth0-d ]]; then
   ifconfig $eth down
   $dhl2 $eth
   exit 0
fi
if [[ "$1" = wlan0-d ]]; then
   ifconfig $int down
   $dhl2 $int
   exit 0
fi
if [[ "$1" = wlan0-u ]]; then
   ifconfig $int up
   $dhl1 $int
   exit 0
fi
if [[ "$1" = wlan1-d ]]; then
   wlanfn
   ifconfig $int down
   $dhl2 $int
   exit 0
fi
if [[ "$1" = usb0-u ]]; then
   ifconfig $usb0 up
   $dhl1 $usb0
   exit 0
fi
if [[ "$1" = usb0-d ]]; then
   ifconfig $usb0 down
   $dhl2 $usb0
   exit 0
fi

menufn () {
[[ -f /tmp/wifitray ]] && /tmp/wifitray
pics3=/usr/share/icons/oxygen/22x22/devices
pics2=/usr/share/pixmaps/puppy
pics=/usr/share/pixmaps
scanres=`iwconfig $int | grep --invert-match 'bytes'`

yad --notification --kill-parent \
    --image=/usr/share/pixmaps/wifiS.png --text="$address:
    $scanres" \
    --command="bash -c on_scanclicks" --menu="Wifi-Scanner-2!killall Wifi-Scanner-2!$pics/wirelessx.png|New-Connection!Wifi-Connect!$pics/wifi224.png|Saved Profiles!Wifi-Profiles!$pics/wireless.png|Browser!defaultbrowser!$pics/browser24.png|Re-connect Wifi!Wifi-Scanner wlan0-u!$pics/wifi124.png|Disconnect Wifi!Wifi-Scanner wlan0-d!$pics/wifi124x.png|+Scanner!Wifi-Scanner-2!$pics/wifi224.png|Stop Scanner!Wifi-Scanner wlan1-d!$pics/wifi224.png|Ethernet connect!Wifi-Scanner eth0-u!$pics3/network-wired.png|Ethernet disconnect!Wifi-Scanner eth0-d!/usr/share/icons/oxygen/22x22/devices/network-wiredx.png|Ethernet 2 connect!Wifi-Scanner eth1-u!$pics3/network-wired.png|Ethernet 2 disconnect!Wifi-Scanner eth1-d!/usr/share/icons/oxygen/22x22/devices/network-wiredx.png|Connect mobile!Wifi-Scanner usb0-u!/usr/share/icons/oxygen/22x22/devices/phone.png|Disconnect mobile!Wifi-Scanner usb0-d!/usr/share/icons/oxygen/22x22/devices/phonex.png|Close Tray!/tmp/wifitray!/usr/share/icons/oxygen/22x22/actions/application-exit.png" &
mpid=$!
task='kill $mpid'
echo "#!/bin/sh
mpid=$mpid
$task
" > /tmp/wifitray
chmod 755 /tmp/wifitray
}

startinfn () {
tin=$int
yad --geometry=$pos --undecorated --no-buttons --skip-taskbar --text "$Resetting $int" --timeout 2 &
CURRENTIPS=$(ip addr show | grep $tin | grep inet | awk '{print $2}')
ifconfig $tin down
for I in $CURRENTIPS; do ip addr del $I dev $tin; done 2> /dev/null
ip route flush dev $tin 2> /dev/null
rm -f /var/db/dhcpcd-${tin}.lease 2> /dev/null
rm -f /var/lib/dhcpcd/dhcpcd-${tin}.lease 2> /dev/null
rm -f /var/db/udhcpc-${tin}.lease 2> /dev/null
rm -f /var/lib/udhcpc/udhcpc-${tin}.lease 2> /dev/null
killall -9 $dhl1 2> /dev/null
killall -9 wpa_supplicant 2> /dev/null
rm -f /var/lib/dhcpcd/*.info 2> /dev/null
rm -f /var/run/dhcpcd*.pid 2> /dev/null
rm -f /var/lib/udhcpc/*.info 2> /dev/null
rm -f /var/run/udhcpc.pid 2> /dev/null
rm -f /var/run/wpa_supplicant/$tin
rfkill unblock $tin 2>/dev/null
ifconfig $tin up
}

startfn () {
. /tmp/interface
for nit in $int1 $int2 $int3 $int4 $int5 $int6
do
if [[ ! -z "$nit" ]]; then
CURRENTIPS=$(ip addr show | grep $nit | grep inet | awk '{print $2}')
ifconfig $nit down
for I in $CURRENTIPS; do ip addr del $I dev $nit; done 2> /dev/null
ip route flush dev $nit 2> /dev/null
rm -f /var/db/dhcpcd-${nit}.lease 2> /dev/null
rm -f /var/lib/dhcpcd/dhcpcd-${nit}.lease 2> /dev/null
rm -f /var/db/udhcpc-${nit}.lease 2> /dev/null
rm -f /var/lib/udhcpc/udhcpc-${nit}.lease 2> /dev/null
rm -f /var/run/wpa_supplicant/$nit
rfkill unblock $nit 2>/dev/null
iwconfig $nit mode managed
ifconfig $nit up
fi
done < /tmp/interface
}

uhohfn () {
uhoh=`cat /tmp/netsel`
if [[ -z "$uhoh" ]]; then
   rm -f /tmp/netsel
   exec "$0"
   exit 0
fi
}

ocfn () {
if [ -z "$password" ]; then
echo "ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
update_config=1
network={
ssid=$netsel1
bssid=$address
key_mgmt=NONE
}
" > /tmp/netsel
elif [[ ! -z "$password" ]]; then
echo "ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
update_config=1
network={
ssid=$netsel1
bssid=$address
scan_ssid=1
password='$password'
#psk=$password1
key_mgmt=WPA2
pairwise=CCMP TKIP
group=CCMP TKIP
}
" > /tmp/netsel
elif [[ ! -z "$usernm" ]]; then
echo "ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
update_config=1
network={
ssid=$netsel1
bssid=$address
identity='$usernm'
password='$password'
key_mgmt=WPA-EAP
eap=PEAP
#ca_cert='/path/to/certificate'
#phase1='peaplabel=0'
phase2='auth=MSCHAPV2'
}
" > /tmp/netsel
fi
diss=`cat /tmp/netsel | grep 'ssid="' | cut -f2 -d'"'`
if [[ /root/.wifi-connect/profiles/"$diss" ]]; then
   cat /tmp/netsel > /root/.wifi-connect/profiles/"$diss"+"$address"
else
   cat /tmp/netsel > /root/.wifi-connect/profiles/"$diss"+"$address"
fi
}

passwordfn () {
userdata=`yad --geometry=$pos --window-icon=/usr/share/pixmaps/wifi24S.png --image="/usr/share/pixmaps/wifiS.png" --title "Password for $netsel1" --form --field=name --field=Password:H --field=Confirm:H`
password=`echo $userdata | cut -f2 -d '|'`
password2=`echo $userdata | cut -f3 -d '|'`
usernm=`echo $userdata | cut -f1 -d '|'`
if [[ -z "$password2" ]]; then
   exit 0
fi
if [[ -z "$password" ]]; then
   exit 0
fi
if [[ "$password2" != "$password" ]]; then
   yad --geometry=$pos --window  --image=/usr/share/pixmaps/wifiS.png --title "Passwords don't match" --text "Try again"
   passwordfn
fi
}

netselfn () {
userdata=`yad --geometry=620$pos --window-icon=/usr/share/pixmaps/wifi24S.png --image="/usr/share/pixmaps/wifiS.png" --title "Copy AP name and mac fields and paste here" --form --field=Essid --field=Mac Address`
id=`echo $userdata | cut -f1 -d '|' | cut -f2 -d'"'`
mad=`echo $userdata | cut -f2 -d '|' | cut -f2 -d' '`
netsel1="$id+$mad"
echo "$netsel1" > /tmp/net
}
export -f netselfn

function on_scanclicks() {
OLDIFCONFIG=`ifconfig | grep -e 'ESSID' -e 'bytes' -e 'bssid'|  grep --invert-match '\x00' | rev | cut -f1 -d ':' | rev | tr " " "#"`
echo -en "$OLDIFCONFIG" > /tmp/onscanclicks
TITLE="$(cat /tmp/onscanclicks 2> /dev/null)"
yad --on-top --selectable-labels --geometry "40x20-10-35" --text "$TITLE" --undecorated --no-buttons --skip-taskbar --timeout 4 &
}
export -f on_scanclicks

connectfn () {
[[ -f /tmp/wifitray ]] && /tmp/wifitray 2>/dev/null
if [ ! -z "$ONN" ]; then
   passwordfn
fi
ocfn
if [[  ! -z "$netsel1" ]]; then
   startinfn
   sleep 2
   if [[ -z "$1" ]]; then
      ranmacfn
      ranmacfn
      ifconfig $int down
      ifconfig $int hw ether $CMD
      ifconfig $int up
      echo "hwaddr=$CMD" >> $HOME/.wifi-connect/wifivars   
   fi
      wpa_supplicant -Dwext -i $int -c/tmp/netsel -B
   dep=`which ifplugstatus`
   if [ -z "$dep" ]; then
      yad --geometry=$pos --undecorated --no-buttons --skip-taskbar --top --text "ifplugstatus NOT found. After connecting please install it." --timeout 4
      sleep 3
   else
      while true
      do
         state=`ifplugstatus $int | grep -e 'link beat detected'`
         if [[ ! -z "$state" ]]; then
            break
         fi
         sleep 1
      done
   fi
yad --geometry=$pos --undecorated --no-buttons --skip-taskbar --top-left --text " Requesting ip address for\n '$netsel1' " --timeout 3 &
$dhl3 $int
   while true
   do
      ipad=`ifconfig | grep inet | sed 's/inet addr/ip/g' | grep --invert-match inet6 | grep Bcast | sed 's/         //'`
      if [[ ! -z "$ipad" ]]; then
         yad --geometry=$pos --undecorated --no-buttons --skip-taskbar --top-left --text "Ip address obtained '$ipad'" --timeout 2
      break
      fi
      sleep 1
   done
fi
menufn &

if [ "$netsel1" = "BTWifi-with-FON" ]; then
   bt
fi
if [[ "$1" = admin ]]; then
exec "$0" && exit
fi
}

menufn
   while [[ -z "$poopp" ]]; do
[[ /tmp/net ]] && rm -f /tmp/net
[[ /tmp/interface ]] && rm -f /tmp/interface
if [[ "$1" = admin ]]; then
inters=`ls /sys/class/net | sed 's/ //g' | grep --invert-match 'lo' | grep --invert-match 'usb' | grep --invert-match 'eth' | tr ' ' '\n'`
echo "$inters"
Q=1
for i in  $inters
do
   ifconfig $i down
   sleep 1
   [[ ! -z "$2" ]] && iwconfig $i mode $2
   sleep 1
   ifconfig $i up
   sleep 1
   echo  "int$Q=$i" >> /tmp/interfaces
   Q=$((Q + 1))
done
fi
cp -f /tmp/interfaces /tmp/interface

if [[ ! -z "$int" ]]; then
   cat /tmp/interfaces | grep --invert-match "$int" > /tmp/interface
fi
. /tmp/interface
int1=$int1
int2=$int2
int3=$int3
int4=$int4
int5=$int5
int6=$int6
startfn
sleep 2
if [[ ! -z "$int1"  ]]; then
these1="--tab=$int1"
else
these1=""
fi
if [[ ! -z "$int2" ]]; then
these2="--tab=$int2"
else
these2=""
fi
if [[ ! -z "$int3" ]]; then
these3="--tab=$int3"
else
these3=""
fi
if [[ ! -z "$int4" ]]; then
these4="--tab=$int4"
else
these4=""
fi
if [[ ! -z "$int5" ]]; then
these5="--tab=$int5"
else
these5=""
fi
if [[ ! -z "$int6" ]]; then
 these6="--tab=$int6"
else
these6=""
fi
if [[ ! -z "$int" ]]; then
case $int in
$int1)
these1="";;
$int2)
these2="";;
$int3)
these3="";;
$int4)
these4="";;
$int5)
these5="";;
$int6)
these6="";;
esac
fi
if [[ "$1" = quick ]]; then
   yad4 --listen --window-icon=/usr/share/pixmaps/leafpad.png --geometry=400x400-80+280 --on-top --notebook --key=$$ --title="Wifi-Scanner-2: Multi-Interface-Wifi" --tab-pos=bottom $these1 $these2 $these3 $these4 $these5 $these6 --timeout 16 &
fi
[[ ! -z "$int1" ]] && ecann1=`iwlist $int1 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac`
[[ ! -z "$int1" ]] && echo "$ecann1" | yad --plug=$$ --tabnum=1 --list --separator=';' --editable --column="$int1 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int1 --hide-column=5 | cut -f1,4 -d';' | sed 's/; /+/' | sed "s/$/+$int1+/" > /tmp/net &
[[ ! -z "$int2" ]] && ecann2=`iwlist $int2 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac`
[[ ! -z "$int2" ]] && echo "$ecann2" | yad --plug=$$ --tabnum=2  --list --separator=';' --editable --column="$int2 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int2 --hide-column=5 | cut -f1,4 -d';' | sed 's/; /+/' | sed "s/$/+$int2+/"  > /tmp/net &
[[ ! -z "$int3" ]] && ecann3=`iwlist $int3 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac`
[[ ! -z "$int3" ]] && echo "$ecann3" | yad --plug=$$ --tabnum=3 --list --separator=';' --editable --column="$int3 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int3 --hide-column=5 | cut -f1,4 -d';' | sed 's/; /+/' | sed "s/$/+$int3+/"  > /tmp/net &
[[ ! -z "$int4" ]] && ecann4=`iwlist $int4 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac`
[[ ! -z "$int4" ]] && echo "$ecann4" | yad --plug=$$ --tabnum=4 --list --separator=';' --editable --column="$int4 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int4 --hide-column=5 | cut -f1,4 -d';' | sed 's/; /+/' | sed "s/$/+$int4+/"  > /tmp/net &
[[ ! -z "$int5" ]] && ecann5=`iwlist $int5 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac`
[[ ! -z "$int5" ]] && echo "$ecann5" | yad --plug=$$ --tabnum=5 --list --separator=';' --editable --column="$int5 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int5 --hide-column=5 | cut -f1,4 -d';' |sed 's/; /+/' | sed "s/$/+$int5+/"  > /tmp/net &
[[ ! -z "$int6" ]] && ecann6=`iwlist $int6 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac`
[[ ! -z "$int6" ]] && echo "$ecann6" | yad --plug=$$ --tabnum=6  --list --separator=';' --editable --column="$int6 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int6 --hide-column=5 | cut -f1,4 -d';' |sed 's/; /+/' | sed "s/$/+$int6+/"  > /tmp/net &
sleep 2
if [[ "$1" = admin ]]; then
   yad4 --window-icon=/usr/share/pixmaps/leafpad.png --geometry=400x400-80+280 --on-top --notebook --key=$$ --title="Wifi-Scanner-2: Multi-Interface-Wifi" --tab-pos=bottom $these1 $these2 $these3 $these4 $these5 $these6
else
   yad4 --window-icon=/usr/share/pixmaps/leafpad.png --geometry=400x400-80+280 --on-top --notebook --key=$$ --title="Wifi-Scanner-2: Multi-Interface-Wifi" --tab-pos=bottom $these1 $these2 $these3 $these4 $these5 $these6 --timeout 20
fi
ret=$?
[[ $ret -eq 1 ]] && rm -f /tmp/{netsel,netself,net*,interface,interfaces} && exit 0
sleep 1
pop=`cat /tmp/net`
  if [[ ! -z "$pop" ]]; then
   netsel1=`cat /tmp/net | grep --invert-match 'null' | head -1 | grep '+' | cut -f1 -d'+'`
   address=`cat /tmp/net | cut -f2 -d'+'`
   int=`cat /tmp/net | cut -f3 -d'+'`
      if [[ ! -z "$netsel1" ]]|[[ ! -z "$address" ]]; then
         ONN=`cat /tmp/net | grep -e '~on~'`
         connectfn &
         sleep 4
      fi
  fi
sleep 12
rm -f /tmp/net
done
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 1980
Location: In The Way

PostPosted: Wed 29 Mar 2017, 16:24    Post subject:  

Question

Let us suppose I connected 6 wifi cards on one pc.

Each card connected by long aerial cable to different sides of the building.

All connected to different APs.

How then could the user select which 'connection' to pipe traffic through? Assuming the user is running FatDog64-710.

I want to be able to switch which active internal connection to use, by script.
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 1980
Location: In The Way

PostPosted: Thu 30 Mar 2017, 04:36    Post subject:  

So I found some info that pointed me to the 'metric' ranking. Together with appropriate changes for the DNS, Gateway settings. Should be easy to script.
Back to top
View user's profile Send private message MSN Messenger 
stemsee

Joined: 27 Jun 2013
Posts: 1980
Location: In The Way

PostPosted: Thu 30 Mar 2017, 04:42    Post subject:  

@MochiMoppel

I think that you might be the one to know a way to have the gui update the info from subsequent scans without having to close the gui to refresh. Is that possible with yad --listen? If so or if you have an idea for some other way would be great. Smile
Back to top
View user's profile Send private message MSN Messenger 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1368
Location: Japan

PostPosted: Thu 30 Mar 2017, 07:45    Post subject:  

@stemsee
Please edit your sample output and remove the 2 extremely long lines. This forum page has become unreadable for me.
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1368
Location: Japan

PostPosted: Sat 01 Apr 2017, 22:10    Post subject:  

Thanks for editing your post.

stemsee wrote:
...have the gui update the info from subsequent scans without having to close the gui to refresh. Is that possible with yad --listen?
More than possible. It's the purpose of this option Wink
Back to top
View user's profile Send private message 
stemsee

Joined: 27 Jun 2013
Posts: 1980
Location: In The Way

PostPosted: Wed 26 Apr 2017, 02:48    Post subject:  

Scales to 8 wifi-interfaces.

Code:
#!/bin/sh
# multi-interface wifi scanner and connection app
# copyright (c) 2017 Marcos Contant
#
res=`xrandr | cut -f8,9,10 -d' ' | cut -f1 -d',' | head -1 | sed 's/ //g'`
XX=`echo $res | cut -f1 -d'x'`
YY=`echo $res | cut -f2 -d'x'`
pos="+$((XX - 640))+$((YY - YY + 20))"
rm /tmp/interface*
rm /tmp/net*
[[ /tmp/wifitray ]] && /tmp/wifitray
rm -f /tmp/wifitray
rm -f /tmp/onclick 2> /dev/null
rm -f /tmp/scans* 2> /dev/null
unset int
interfacefn () {
for wit in `ls /sys/class/net`
do
case $wit in
   eth0|enp2s0f2) eth=$wit;;
   eth1) eths=$wit;;
   enp0s20u3|usb0) usb0=$wit;;
esac
done
}

wlanfn () {
inters=`ls /sys/class/net | sed 's/ //g' | grep --invert-match 'lo' | grep --invert-match 'usb' | grep --invert-match 'eth' | yad --window-icon=/usr/share/pixmaps/wireless.png --title="Wifi-Profi $dhclu $dhcld" --geometry=300$pos --list --separator=' ' --multiple --column="Select Interface" | tr '\n' ' '`
ret=$?
[[ $ret -eq 1 ]] && exit 0
echo "$inters"
Q=1
for i in  $inters
do
echo  "int$Q=$i" >> /tmp/interfaces
Q=$((Q + 1))
done
}
wlanfn

depsfn () { # check dependencies
   dhclu=`busybox which udhcpc`
   dhclu=`echo $dhclu | rev | cut -f1 -d'/' | rev`
   dhcld=`busybox which dhcpcd`
   dhcld=`echo $dhcld | rev | cut -f1 -d'/' | rev`
   if [ -z "$dhcld" ]; then
      dhl1="udhcpc -A 8 -p /var/run/udhcpc.pid -s /etc/udhcpc.script -i"
      dhl2="/etc/udhcpc.script deconfig"
   elif [[ ! -z "$dhcld" ]]; then
      dhl3="dhcpcd -z"
      dhl1="dhcpcd"
      dhl2="dhcpcd -k"
   elif [[ -z "$dhclu" && -z "$dhcld" ]]; then
      zenity --info --text "$dhclu and $dhcld not found"
   fi
}
depsfn

if [[ "$1" = eth0-u ]]; then
   ifconfig $eth up
   $dhl3 $eth
   exit 0
fi
if [[ "$1" = eth0-d ]]; then
   ifconfig $eth down
   $dhl2 $eth
   exit 0
fi
if [[ "$1" = wlan0-d ]]; then
   ifconfig $int down
   $dhl2 $int
   exit 0
fi
if [[ "$1" = wlan0-u ]]; then
   ifconfig $int up
   $dhl3 $int
   exit 0
fi
if [[ "$1" = wlan1-d ]]; then
   wlanfn
   ifconfig $int down
   $dhl2 $int
   exit 0
fi
if [[ "$1" = usb0-u ]]; then
   ifconfig $usb0 up
   $dhl3 $usb0
   exit 0
fi
if [[ "$1" = usb0-d ]]; then
   ifconfig $usb0 down
   $dhl2 $usb0
   exit 0
fi

menufn () {
[[ -f /tmp/wifitray ]] && /tmp/wifitray
pics3=/usr/share/icons/oxygen/22x22/devices
pics2=/usr/share/pixmaps/puppy
pics=/usr/share/pixmaps
scanres=`iwconfig $int | grep --invert-match 'bytes'`

yad --notification --kill-parent \
    --image=/usr/share/pixmaps/wifiS.png --text="$address:
    $scanres" \
    --command="bash -c on_scanclicks" --menu="Wifi-Scanner-2!killall Wifi-Scanner-2!$pics/wirelessx.png|New-Connection!Wifi-Connect!$pics/wifi224.png|Saved Profiles!Wifi-Profiles!$pics/wireless.png|Browser!defaultbrowser!$pics/browser24.png|Re-connect Wifi!Wifi-Scanner-2 wlan0-u!$pics/wifi124.png|Disconnect Wifi!Wifi-Scanner-2 wlan0-d!$pics/wifi124x.png|+Scanner!Wifi-Scanner-2!$pics/wifi224.png|Stop Scanner!Wifi-Scanner-2 wlan1-d!$pics/wifi224.png|Ethernet connect!Wifi-Scanner-2 eth0-u!$pics3/network-wired.png|Ethernet disconnect!Wifi-Scanner-2 eth0-d!/usr/share/icons/oxygen/22x22/devices/network-wiredx.png|Ethernet 2 connect!Wifi-Scanner-2 eth1-u!$pics3/network-wired.png|Ethernet 2 disconnect!Wifi-Scanner-2 eth1-d!/usr/share/icons/oxygen/22x22/devices/network-wiredx.png|Connect mobile!Wifi-Scanner-2 usb0-u!/usr/share/icons/oxygen/22x22/devices/phone.png|Disconnect mobile!Wifi-Scanner-2 usb0-d!/usr/share/icons/oxygen/22x22/devices/phonex.png|Close Tray!/tmp/wifitray!/usr/share/icons/oxygen/22x22/actions/application-exit.png" &
mpid=$!
task='kill $mpid'
echo "#!/bin/sh
mpid=$mpid
$task
" > /tmp/wifitray
chmod 755 /tmp/wifitray
}

startinfn () {
for tin in $inters
do
yad --geometry=$pos --undecorated --no-buttons --skip-taskbar --text "$Resetting $tin" --timeout 2 &
CURRENTIPS=$(ip addr show | grep $tin | grep inet | awk '{print $2}')
ifconfig $tin down
for I in $CURRENTIPS; do ip addr del $I dev $tin; done 2> /dev/null
ip route flush dev $tin 2> /dev/null
rm -f /var/db/dhcpcd-${tin}.lease 2> /dev/null
rm -f /var/lib/dhcpcd/dhcpcd-${tin}.lease 2> /dev/null
rm -f /var/db/udhcpc-${tin}.lease 2> /dev/null
rm -f /var/lib/udhcpc/udhcpc-${tin}.lease 2> /dev/null
rm -f /var/run/wpa_supplicant/$tin
rfkill unblock $tin 2>/dev/null
ifconfig $tin up
done
}

uhohfn () {
uhoh=`cat /tmp/netsel`
if [[ -z "$uhoh" ]]; then
   rm -f /tmp/netsel
   $0
   exit 0
fi
}

ocfn () {
if [ -z "$password" ]; then
echo "ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
update_config=1
network={
ssid=$netsel1
bssid=$address
key_mgmt=NONE
}
" > /tmp/netsel
elif [[ ! -z "$password" ]]; then
echo "ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
update_config=1
network={
ssid=$netsel1
bssid=$address
scan_ssid=1
password='$password'
#psk=$password1
key_mgmt=WPA2
pairwise=CCMP TKIP
group=CCMP TKIP
}
" > /tmp/netsel
elif [[ ! -z "$usernm" ]]; then
echo "ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
update_config=1
network={
ssid=$netsel1
bssid=$address
identity='$usernm'
password='$password'
key_mgmt=WPA-EAP
eap=PEAP
#ca_cert='/path/to/certificate'
#phase1='peaplabel=0'
phase2='auth=MSCHAPV2'
}
" > /tmp/netsel
fi
diss=`cat /tmp/netsel | grep 'ssid="' | cut -f2 -d'"'`
if [[ /root/.wifi-connect/profiles/"$diss" ]]; then
   cat /tmp/netsel > /root/.wifi-connect/profiles/"$diss"+"$address"
else
   cat /tmp/netsel > /root/.wifi-connect/profiles/"$diss"+"$address"
fi
}

passwordfn () {
userdata=`yad --geometry=$pos --window-icon=/usr/share/pixmaps/wifi24S.png --image="/usr/share/pixmaps/wifiS.png" --title "Password for $netsel1" --form --field=name --field=Password:H --field=Confirm:H`
password=`echo $userdata | cut -f2 -d '|'`
password2=`echo $userdata | cut -f3 -d '|'`
usernm=`echo $userdata | cut -f1 -d '|'`
#if [[ -z "$password2" ]]; then
   #exit 0
#fi
#if [[ -z "$password" ]]; then
   #exit 0
#fi
if [[ "$password2" != "$password" ]]; then
   yad --geometry=$pos --window  --image=/usr/share/pixmaps/wifiS.png --title "Passwords don't match" --text "Try again"
   passwordfn
fi
}

netselfn () {
userdata=`yad --geometry=620$pos --window-icon=/usr/share/pixmaps/wifi24S.png --image="/usr/share/pixmaps/wifiS.png" --title "Copy AP name and mac fields and paste here" --form --field=Essid --field=Mac Address`
id=`echo $userdata | cut -f1 -d '|' | cut -f2 -d'"'`
mad=`echo $userdata | cut -f2 -d '|' | cut -f2 -d' '`
netsel1="$id+$mad"
echo "$netsel1" > /tmp/net
}
export -f netselfn

function on_scanclicks() {
OLDIFCONFIG=`ifconfig | grep -e 'ESSID' -e 'bytes' -e 'bssid'|  grep --invert-match '\x00' | rev | cut -f1 -d ':' | rev | tr " " "#"`
echo -en "$OLDIFCONFIG" > /tmp/onscanclicks
TITLE="$(cat /tmp/onscanclicks 2> /dev/null)"
yad --on-top --selectable-labels --geometry "40x20-10-35" --text "$TITLE" --undecorated --no-buttons --skip-taskbar --timeout 4 &
}
export -f on_scanclicks

connectfn () {
[[ -f /tmp/wifitray ]] && /tmp/wifitray 2>/dev/null
if [ -z "$ONN" ]; then
   passwordfn
fi
ocfn
if [[  ! -z "$netsel1" ]]; then
   startinfn
   sleep 2
      ranmacfn
      ranmacfn
      ifconfig $int down
      ifconfig $int hw ether $CMD
      ifconfig $int up
      echo "hwaddr=$CMD" >> $HOME/.wifi-connect/wifivars      
      wpa_supplicant -Dwext -i $int -c/tmp/netsel -B
   dep=`busybox which ifplugstatus`
   if [ -z "$dep" ]; then
      yad --geometry=$pos --undecorated --no-buttons --skip-taskbar --top --text "ifplugstatus NOT found. After connecting please install it." --timeout 4
      sleep 3
   else
      while true
      do
         state=`ifplugstatus $int | grep -e 'link beat detected'`
         if [[ ! -z "$state" ]]; then
            break
         fi
         sleep 1
      done
   fi
yad --geometry=$pos --undecorated --no-buttons --skip-taskbar --top-left --text " Requesting ip address for\n '$netsel1' " --timeout 3 &
$dhl3 $int
   while true
   do
      ipad=`ifconfig | grep inet | sed 's/inet addr/ip/g' | grep --invert-match inet6 | grep Bcast | sed 's/         //'`
      if [[ ! -z "$ipad" ]]; then
         yad --geometry=$pos --undecorated --no-buttons --skip-taskbar --top-left --text "Ip address obtained '$ipad'" --timeout 2
      break
      fi
      sleep 1
   done
fi
menufn &
if [[ "$netsel1" = "BTWifi-with-FON" ]]; then
   bt &
fi

#exec "$0"
}

[[ -f /tmp/wifitray ]] && /tmp/wifitray 2>/dev/null

menufn
startinfn
while [[ -z "$poopp" ]]; do
[[ /tmp/net ]] && rm -f /tmp/net
#[[ /tmp/interface ]] && rm -f /tmp/interface
if [[ "$1" = admin ]]; then
inters=`ls /sys/class/net | sed 's/ //g' | grep --invert-match 'lo' | grep --invert-match 'usb' | grep --invert-match 'eth' | tr ' ' '\n'`
echo "$inters"
Q=1
for i in  $inters
do
   ifconfig $i down
   sleep 1
   [[ ! -z "$2" ]] && iwconfig $i mode $2
   sleep 1
   ifconfig $i up
   sleep 1
   echo  "int$Q=$i" >> /tmp/interfaces
   Q=$((Q + 1))
done
#[[ /tmp/interface ]] && rm -f /tmp/interface
fi
while true
do
if [[ ! -z "$int" ]]; then
   cat /tmp/interfaces | grep --invert-match "$int" > /tmp/interface
   . /tmp/interface
fi
[[  ! -z "$int"  ]] && . /tmp/interface

. /tmp/interfaces
int1=$int1
int2=$int2
int3=$int3
int4=$int4
int5=$int5
int6=$int6
int7=$int7
int8=$int8
if [[ ! -z "$int1"  ]]; then
   these1="--tab=$int1"
else
   these1=""
fi
if [[ ! -z "$int2" ]]; then
   these2="--tab=$int2"
else
   these2=""
fi
if [[ ! -z "$int3" ]]; then
   these3="--tab=$int3"
else
   these3=""
fi
if [[ ! -z "$int4" ]]; then
   these4="--tab=$int4"
else
   these4=""
fi
if [[ ! -z "$int5" ]]; then
   these5="--tab=$int5"
else
   these5=""
fi
if [[ ! -z "$int6" ]]; then
   these6="--tab=$int6"
else
   these6=""
fi
if [[ ! -z "$int7" ]]; then
   these7="--tab=$int7"
else
   these7=""
fi
if [[ ! -z "$int8" ]]; then
   these8="--tab=$int8"
else
   these8=""
fi
if [[ ! -z "$int" ]]; then
case $int in
$int1) these1="";;
$int2) these2="";;
$int3) these3="";;
$int4) these4="";;
$int5) these5="";;
$int6) these6="";;
$int7) these7="";;
$int8) these8="";;
esac
fi
if [[ -z "$int1" ]]; then
   exit 0
fi
these="$these1 $these2 $these3 $these4 $these5 $these6 $these7 $these8"
[[ ! -z "$int1" ]] && ecann1=`iwlist $int1 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac | yad --plug=$$ --tabnum=1 --list --separator=';' --editable --column="$int1 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int1 --hide-column=5 | cut -f1,2,4 -d';' | sed 's/; /+/g' | sed "s/$/+$int1+/" > /tmp/net &`
[[ ! -z "$int2" ]] && ecann2=`iwlist $int2 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac | yad --plug=$$ --tabnum=2 --list --separator=';' --editable --column="$int2 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int2 --hide-column=5 | cut -f1,2,4 -d';' | sed 's/; /+/g' | sed "s/$/+$int2+/" > /tmp/net &`
[[ ! -z "$int3" ]] && ecann3=`iwlist $int3 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac | yad --plug=$$ --tabnum=3 --list --separator=';' --editable --column="$int3 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int3 --hide-column=5 | cut -f1,2,4 -d';' | sed 's/; /+/g' | sed "s/$/+$int3+/" > /tmp/net &`
[[ ! -z "$int4" ]] && ecann4=`iwlist $int4 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac | yad --plug=$$ --tabnum=4 --list --separator=';' --editable --column="$int4 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int4 --hide-column=5 | cut -f1,2,4 -d';' | sed 's/; /+/g' | sed "s/$/+$int4+/" > /tmp/net &`
[[ ! -z "$int5" ]] && ecann5=`iwlist $int5 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac | yad --plug=$$ --tabnum=5 --list --separator=';' --editable --column="$int5 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int5 --hide-column=5 | cut -f1,2,4 -d';' | sed 's/; /+/g' | sed "s/$/+$int5+/" > /tmp/net &`
[[ ! -z "$int6" ]] && ecann6=`iwlist $int6 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac | yad --plug=$$ --tabnum=6 --list --separator=';' --editable --column="$int6 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int6 --hide-column=5 | cut -f1,2,4 -d';' | sed 's/; /+/g' | sed "s/$/+$int6+/" > /tmp/net &`
[[ ! -z "$int7" ]] && ecann7=`iwlist $int7 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac | yad --plug=$$ --tabnum=7 --list --separator=';' --editable --column="$int7 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int7 --hide-column=5 | cut -f1,2,4 -d';' | sed 's/; /+/g' | sed "s/$/+$int7+/" > /tmp/net &`
[[ ! -z "$int8" ]] && ecann8=`iwlist $int8 scan | grep -e 'ESSID' -e 'Quality' -e 'Address' -e 'key' | sed 's/          //g' | sed 's/   / /g' | sed 's/   / /g' | sed 's/  / /g' | sed 's/Quality=/  /g' | sed 's/level=/    /g' | sed 's/ESSID://g' | sed 's/key:on/~on~/g' | sed 's/key:off/~off~/g' | sed 's/Encryption//g' | sed 's/ Signal//g' | sed 's/- Address: / /g' | sed 's|Cell ...|\n|g' | sed 's/  //'  | sed 's/ - //g' | tac | yad --plug=$$ --tabnum=8 --list --separator=';' --editable --column="$int8 found these APs" --column=Password --column=Quality/Level --column=MAC --column=$int8 --hide-column=5 | cut -f1,2,4 -d';' | sed 's/; /+/g' | sed "s/$/+$int8+/" > /tmp/net &`
sleep 2
yad4 --window-icon=/usr/share/pixmaps/leafpad.png --geometry=720x400-80+280 --on-top --notebook --key=$$ --title="Wifi-Scanner-2: Multi-Interface-Wifi" --tab-pos=bottom $these --timeout 30
   ret=$?
   [[ $ret -eq 1 ]] && rm -f /tmp/{netsel,netself,net*,interface} && exit 0
   empty=`cat /tmp//net`
 
   if [[ ! -z "$empty" ]]; then
   [[ -f /tmp/net ]] && netsel1=`cat /tmp/net | grep --invert-match 'null' | head -1 | grep '+' | cut -f1 -d'+'`
   address=`cat /tmp/net | cut -f3 -d'+'`
   int=`cat /tmp/net | cut -f4 -d'+'`
   #export int
   inters=`echo "$inters" | tr ' ' '\n' | grep --invert-match $int | tr '\n' ' '`
   #export inters
      if [[ ! -z "$netsel1" ]]|[[ ! -z "$address" ]]; then
         ONN=`cat /tmp/net | grep -e '~off~'`
         connectfn &
      fi
   fi
done
done
Back to top
View user's profile Send private message MSN Messenger 
Display posts from previous:   Sort by:   
Page 1 of 2 [23 Posts]   Goto page: 1, 2 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1902s ][ Queries: 12 (0.0050s) ][ GZIP on ]