Multi-Wifi-Interface scan and connect "Wifi-Scanner-2"

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
stemsee

Multi-Wifi-Interface scan and connect "Wifi-Scanner-2"

#1 Post by stemsee »

Multi-Interface Wifi Connector and Scanner.

Can use upto 8 wireless interfaces in tabbed windows. Select AP from any tab to connect to it. Continue scanning on other interfaces.

Supports WPA2-PSK, PEAP, OPEN network configurations as I have not encountered WPA/WEP recently so I didn't add support but help yourself.

Creates saved profiles according to ssid and bssid.

see further on for script
Attachments
xscreenshot-20170325T182812.png
(46.19 KiB) Downloaded 719 times
Last edited by stemsee on Sun 24 Dec 2017, 19:44, edited 6 times in total.

User avatar
6502coder
Posts: 677
Joined: Mon 23 Mar 2009, 18:07
Location: Western United States

#2 Post by 6502coder »

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.

stemsee

#3 Post by stemsee »

There's no good reason ... only ignorance!

stemsee

#4 Post by stemsee »

I got it working! In a round about way!
Last edited by stemsee on Thu 26 Oct 2017, 13:43, edited 1 time in total.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#5 Post by MochiMoppel »

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: Select all

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: Select all

[[ "$int" != "$int1" ]] &&   ecann1=`iwlist $int1 scan | ... 
[[ "$int" != "$int1" ]] &&   echo "$ecann1" | ...
[[ "$int" != "$int2" ]] &&   ecann2=`iwlist $int2 scan | ... 
[[ "$int" != "$int2" ]] &&   echo "$ecann2" | ...

stemsee

#6 Post by stemsee »

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?
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.

Code: Select all

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: Select all

[[ "$int" != "$int1" ]] &&   ecann1=`iwlist $int1 scan | ... 
[[ "$int" != "$int1" ]] &&   echo "$ecann1" | ...
[[ "$int" != "$int2" ]] &&   ecann2=`iwlist $int2 scan | ... 
[[ "$int" != "$int2" ]] &&   echo "$ecann2" | ...
I will try this!

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#7 Post by MochiMoppel »

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: Select all

# 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.

stemsee

#8 Post by stemsee »

Thanks for that MochiMoppel

Here is a sample output of iwlist scan on my machine

Code: Select all

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: Select all

"BTWifi-with-Fon" **:**:**:**:** on 29/70 -87 2.4 1
cheers
stemsee
Last edited by stemsee on Thu 30 Mar 2017, 21:32, edited 1 time in total.

stemsee

#9 Post by stemsee »

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: Select all

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.
Last edited by stemsee on Thu 26 Oct 2017, 13:46, edited 2 times in total.

stemsee

#10 Post by stemsee »

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.

stemsee

#11 Post by stemsee »

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.

stemsee

#12 Post by stemsee »

@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. :-)

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#13 Post by MochiMoppel »

@stemsee
Please edit your sample output and remove the 2 extremely long lines. This forum page has become unreadable for me.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#14 Post by MochiMoppel »

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:

slavvo67
Posts: 1610
Joined: Sat 13 Oct 2012, 02:07
Location: The other Mr. 305

#15 Post by slavvo67 »

Forgive my ignorance but why more than one wifi interface?

stemsee

#16 Post by stemsee »

I own 5 usb wifi dongles plus the inbuilt pcie. Each card has different sensitivities and I use extension aerial cables to receive scan data from different sides of my building. Scanning with several wifi cards lets me compare the strengths and weaknesses of he cards. Also two interfaces for joining network and creating hotspot. Also just because I wanted to program it.

Eventually i want to develope auto switching between several cards.

slavvo67
Posts: 1610
Joined: Sat 13 Oct 2012, 02:07
Location: The other Mr. 305

#17 Post by slavvo67 »

I have a number of wifi dongles, as well. Never thought to use them in that way. I've been wanting to try the hotspot idea for a while.... Any tips?

stemsee

#18 Post by stemsee »

Wifi-HotSpot uses create_ap backend. 'create_ap' gets compiled on first use but the devx must be loaded. Or you can simply cd to /usr/sbin/create_ap-master then open terminal there and

Code: Select all

make install
check installation and get useful info

Code: Select all

create_ap
Wifi-HotSpot gui has information button
Attachments
xscreenshot-20170610T073644.png
(29.39 KiB) Downloaded 605 times
whm.png
click larger icon for full info.
(23.58 KiB) Downloaded 600 times
xscreenshot-20170610T073658.png
(20.43 KiB) Downloaded 605 times

stemsee

#19 Post by stemsee »

see last or first post
Last edited by stemsee on Thu 26 Oct 2017, 13:47, edited 8 times in total.

stemsee

#20 Post by stemsee »

The one thing I would like to add now is a static tab for control options.

Post Reply